SSH框架整合配置文件

SSH整合配置文件

struts2配置文件详解

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
    <!-- 解决post提交乱码 -->
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>
    <!-- 动态方法调用 -->
    <constant name="struts.deMode" value="true"></constant>
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    	<!-- package中的 name表示包名,namespace表示在浏览器输入地址时的前面部分,localhost:8080/+namesapce+<action>标签中的name -->
    	<package name="hello" namespace="/" extends="struts-default">
    	

    	<interceptors>
    		    	<!-- 注册拦截器 -->
    		    	<interceptor name="MyIntercept" class="com.rabbit.web.intercept.MyIntercept"></interceptor>
    		    	<!-- 注册拦截器栈 -->
    		    	<interceptor-stack name="MyStack">
    		    		<!-- 引入自己创建的拦截器 -->
    		    		<interceptor-ref name="MyIntercept">
    		    			<!-- 配置不拦截的方法() -->
    		    			<param name="excludeMethods">login,regist</param>
    		    		</interceptor-ref>
    		    		<!-- 引入struts写好的拦截器(20个) -->
    		    		<interceptor-ref name="defaultStack"></interceptor-ref>
    		    	</interceptor-stack>
    	</interceptors>
    	<!-- 指定包中的默认拦截器栈 -->
    	<default-interceptor-ref name="MyStack"></default-interceptor-ref>
    		<global-results>
    			<result name="toLogin" type="redirect">/index.jsp</result>
    		</global-results>
    		<!-- 通配符 -->
    		<global-allowed-methods>regex:.*</global-allowed-methods>
    		<!-- name 输入进网址的名称路径 class 就是这个Action的完整路径 method:需要调用的方法 -->
    		
    		<action name="LoginAction_*" class="com.rabbit.web.LoginAction" method="{1}">
    			<result name="success">/main.jsp</result>
    			<result name="sorry" >/regist.jsp</result>
    			<result name="addsuccess" type="redirect">/login.jsp</result>
    		</action>
    	</package>
    	
    	<!-- 验证码不走拦截器 -->
    	<package name="YzmPackage" namespace="/" extends="struts-default">
    		<global-allowed-methods>regex:.*</global-allowed-methods>
    		<action name="YzmAction_*" class="com.rabbit.web.YzmAction" method="{1}">
    		</action>
    	</package>
    </struts>

Spring 配置文件详解

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">
<!-- 读取db.properties文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置c3p0连接池 -->
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
		<property name="driverClass" value="${jdbc.driverClass}"></property>
		<property name="user" value="${jdbc.user}"></property>
		<property name="password" value="${jdbc.password}"></property>
</bean>

<!-- 核心事务管理器 -->
<bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
		<tx:method name="save*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
		<tx:method name="persist*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
		<tx:method name="update*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
		<tx:method name="modify*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
		<tx:method name="delete*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
		<tx:method name="remove*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
		<tx:method name="get*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="true" />
		<tx:method name="find*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="true" />
		<tx:method name="*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false" />
	</tx:attributes>
</tx:advice>
<!-- 配置通知织入目标对象 -->
<aop:config>
	<aop:pointcut expression="execution(* com.rabbit.service.*Impl.*(..))" id="txPc"/>
	<aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/>
</aop:config>

<!-- 开启注解配置 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager"/> -->







<!-- 将SessionFactory配置到spring 注意hibernate的版本 -->
<!-- 加载配置方案1:仍然使用外部hibernate.cfg.xml配置信息 -->
<!-- <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
	<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean> -->
<!-- 加载配置方案2:在spring中配置放置hibernate -->
<bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
	<!-- 注入c3p0到sessionfactory、DataSource -->
	<property name="dataSource" ref="dataSource"></property>
	<!-- 配置hibernate基本信息 -->
	<property name="hibernateProperties">
		<props>
			<!-- <prop key="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</prop>
			<prop key="hibernate.connection.url">jdbc:mysql:///crm_32?serverTimezone=GMT%2B8</prop>
			<prop key="hibernate.connection.username">root</prop>
			<prop key="hibernate.connection.password">admin</prop> -->
			<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
			
			<prop key="hibernate.show_sql">true</prop>
			<prop key="hibernate.format_sql">true</prop>
			<prop key="hibernate.hbm2ddl.auto">update</prop>
		</props>
	</property>
	<!-- 引入orm元数据 只配包名就可以 -->
	<property name="mappingDirectoryLocations" value="classpath:com/rabbit/domain">
		
	</property>
</bean>
<!-- Action配置 
	注意:Action对象的作用范围一定是多例的,这样猜符合struts2的架构
-->
<bean name="userAction" class="com.rabbit.web.UserAction" scope="prototype">
	<property name="userService" ref="userService"></property>
</bean>
<bean name="customerAction" class="com.rabbit.web.CustomerAction" scope="prototype">
	<property name="customerService" ref="customerService"></property>
</bean>
<bean name="linkManAction" class="com.rabbit.web.LinkManAction" scope="prototype">
	<property name="linkManService" ref="linkManService"></property>
</bean>
<bean name="baseDictAction" class="com.rabbit.web.BaseDictAction" scope="prototype">
	<property name="baseDictService" ref="baseDictService"></property>
</bean>
<!-- service配置 -->
<bean name="userService" class="com.rabbit.service.UserServiceImpl">
	<property name="userDao" ref="userDao"></property>
</bean>
<bean name="customerService" class="com.rabbit.service.CustomerServiceImpl">
	<property name="customerDao" ref="customerDao"></property>
</bean>
<bean name="linkManService" class="com.rabbit.service.LinkManServiceImpl">
	<property name="linkManDao" ref="linkManDao"></property>
</bean>
<bean name="baseDictService" class="com.rabbit.service.BaseDictServiceImpl">
	<property name="bdd" ref="baseDictDao"></property>
</bean>

<!-- dao -->
<bean name="userDao" class="com.rabbit.dao.UserDaoImpl">
	<!-- 注入sessionfactory -->
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="customerDao" class="com.rabbit.dao.CustomerDaoImpl">
	<!-- 注入sessionfactory -->
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="linkManDao" class="com.rabbit.dao.LinkManDaoImpl">
	<!-- 注入sessionfactory -->
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="baseDictDao" class="com.rabbit.dao.BaseDictDaoImpl">
	<!-- 注入sessionfactory -->
	<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

</beans>

hibernate 配置文件详解

ORM元数据配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <!-- package 属性 填写一个包名,写了包名之后,需要填写完整类名的可以直接写简单类名 -->
    <hibernate-mapping package="com.rabbit.domain">
    	<class name="Customer" table="cst_customer">
    		<id name="cust_id" column="cust_id">
    			<generator class="native"></generator>
    		</id>
    		<property name="cust_name" column="cust_name"></property>
    		<!-- <property name="cust_source" column="cust_source"></property>
    		<property name="cust_industyr" column="cust_industyr"></property>
    		<property name="cust_level" column="cust_level"></property> -->
    		<property name="cust_linkman" column="cust_linkman"></property>
    		<property name="cust_phone" column="cust_phone"></property>
    		<property name="cust_mobile" column="cust_mobile"></property>
    
    		<!-- 多对一 -->
    		<many-to-one name="cust_source" column="cust_source" class="BaseDict"></many-to-one>
    		<many-to-one name="cust_industry" column="cust_industry" class="BaseDict"></many-to-one>
    		<many-to-one name="cust_level" column="cust_level" class="BaseDict"></many-to-one>
    	</class>
    </hibernate-mapping>

hibernamate主配置文件:名为hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
	<hibernate-configuration>
		<session-factory>
			 
			 <!-- 数据库驱动 -->
			<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
			<!-- 连接数据库url -->
			<property name="hibernate.connection.url">jdbc:mysql:///crm_32?serverTimezone=GMT%2B8</property>
			<!-- 数据库用户名 -->
			<property name="hibernate.connection.username">root</property>
			<!-- 数据库密码 -->
			<property name="hibernate.connection.password">admin</property>
			<!-- 数据库方言
					在不同的数据库中,sql语法略有区别,指定方言可以让hibernate在生存sql语句时,针对数据库方言实现
			 -->
			 <!-- org.hibernate.dialect.MySQLDialect -->
			<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
			<!-- #hibernate.show_sql true 	打印sql语句
					#hibernate.format_sql true	格式化sql语句
			-->
			<!-- 可选 -->
			<property name="hibernate.show_sql">true</property>
			<property name="hibernate.format_sql">true</property>
			<!-- 
					#hibernate.hbm2ddl.auto update			(推荐使用)自动生成表,如果已经存在,就不会再生成,如果表有变动会自动更新表,不会删除任何数据
	 -->
			<property name="hibernate.hbm2ddl.auto">update</property>
			<!-- 引入orm元数据:
					路径书写,填写src下的路劲;
			 -->
			<mapping resource="com/rabbit/domain/Customer.hbm.xml"/>
			<mapping resource="com/rabbit/domain/LinkMan.hbm.xml"/>
			<mapping resource="com/rabbit/domain/User.hbm.xml"/>
		</session-factory>
	</hibernate-configuration>

web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>SSSH_CRM</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
  <!-- Spring 配置文件加载 -->
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <filter>
    <filter-name>openSessionInView</filter-name>
    <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>openSessionInView</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- 开启struts2 -->
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值