SSH框架集成详细解读(配源码)

在三大框架集成中需要几个配置文件,包括如下:

web.xml配置文件:

(1)配置struts2的过滤器 (2)spring框架的配置文件 (3)会话监听器 (4)编码的配置

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns=""xmlns:xsi=""xsi:schemaLocation=" "><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><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><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><filter><filter-name>OpenSessionInViewFilter</filter-name><filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>OpenSessionInViewFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><filter><filter-name>CharacterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param></filter><filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>applicationContext.xml配置文件:

(1)读取dbcp数据源 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> (2)Hibernate的常用属性配置(注意到一定要配置方言dialect,否者会报错的) (3)事务管理的配置 (4)bean的配置

<?xml version="1.0" encoding="UTF-8"?><beans xmlns=""xmlns:xsi="" xmlns:aop=""xmlns:context="" xmlns:tx=""xsi:schemaLocation=" http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><context:property-placeholder location="classpath:dbcpconfig.properties" /><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName"><value>${driverClassName}</value></property><property name="url"><value>${url}</value></property><property name="username"><value>${username}</value></property><property name="password"><value>${password}</value></property><property name="initialSize"><value>${initialSize}</value></property><property name="maxActive"><value>${maxActive}</value></property><property name="maxIdle"><value>${maxIdle}</value></property><property name="minIdle"><value>${minIdle}</value></property><property name="maxWait"><value>${maxWait}</value></property></bean><bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><property name="mappingResources"><list><value>cn/csu/edu/graduateDesign/domain/TestUser.hbm.xml</value></list></property></bean><!– hibernate的事务管理器 –><bean id="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!– 事务传播特性 –><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="add*" propagation="REQUIRED" /><tx:method name="delete*" propagation="REQUIRED" /><tx:method name="modify*" propagation="REQUIRED" /><tx:method name="*" propagation="NOT_SUPPORTED" /></tx:attributes></tx:advice><aop:config><aop:pointcut expression="execution (* cn.csu.edu.graduateDesign.service.*.*(..))"id="AllMethod" /><aop:advisor advice-ref="txAdvice" pointcut-ref="AllMethod" /></aop:config><bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory" /></bean><bean id="TestUserAction" class="cn.csu.edu.graduateDesign.web.struts.TestUserAction"><property name="testUserService" ref="testUserService"/></bean><bean id="testUserService" class="cn.csu.edu.graduateDesign.service.impl.TestUserServiceImpl"><property name="testUserDao" ref="testUserDao"/></bean><bean id="testUserDao" class="cn.csu.edu.graduateDesign.dao.impl.TestUserDaoHibernateImpl"><property name="hibernateTemplate" ref="hibernateTemplate"/></bean></beans>(注:配置文件的bean里面引用了hibernateTemplate,这个是spring价包里面的,其他的bean,就是我自己

定义的一些类,在这里面利用set注入的方式进行实例化了,这里面的实例互相引用,,我相信大家应该看得

懂)

struts.xml配置文件:

以诚感人者,人亦诚而应。

SSH框架集成详细解读(配源码)

相关文章:

你感兴趣的文章:

标签云: