antlr-2.7.6.jar
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
commons-collections-3.1.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
dom4j-1.6.1.jar
freemarker-2.3.19.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate3.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
log4j-1.2.17.jar
mysql-connector-java-5.1.13-bin.jar
ognl-3.0.6.jar
slf4j-api-1.6.1.jar
spring-aop-3.2.16.RELEASE.jar
spring-aspects-3.2.16.RELEASE.jar
spring-beans-3.2.16.RELEASE.jar
spring-context-3.2.16.RELEASE.jar
spring-core-3.2.16.RELEASE.jar
spring-expression-3.2.16.RELEASE.jar
spring-jdbc-3.2.16.RELEASE.jar
spring-orm-3.2.16.RELEASE.jar
spring-test-3.2.16.RELEASE.jar
spring-tx-3.2.16.RELEASE.jar
spring-web-3.2.16.RELEASE.jar
struts2-core-2.3.15.3.jar
struts2-spring-plugin-2.3.15.3.jar
xwork-core-2.3.15.3.jar
1. 配置web.xml文件
<!-- 配置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>
<!-- 保证只加载一次配置文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置配置文件的路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
2. 在struts.xml中的配置
配置常量:
<!-- 配置struts与spring整合 -->
<constant name="struts.objectFactory" value="spring"></constant>
<!-- 配置按属性名注入 -->
<constant name="struts.objectFactory.spring.autoWire" value="name"></constant>
<!-- 方法1: action由struts创建,引用类型的属性由spring提供(此时,action使用全类名) -->
<package name="default" namespace="/" extends="struts-default">
<action name="productAction_*" class="cn.xiaoge.web.action.ProductAction"
method="{1}">
<result name="success">/index.jsp</result>
</action>
</package>
同时,在applicationContext中进行配置
<!-- 配置商品的业务类 -->
<bean name="productService" class="cn.xiaoge.service.impl.ProductServiceImpl"></bean>
在applicationContext.xml中进行配置
<!-- 配置商品的业务类 -->
<bean name="productService" class="cn.xiaoge.service.impl.ProductServiceImpl">
</bean>
<!-- 配置ProductAction -->
<bean name="productAction" class="cn.xiaoge.web.action.ProductAction">
<property name="productService" ref="productService"></property>
</bean>
在struts.xml中进行配置
<!-- 方法2: action作为bean在applicationContext.xml中进行配置 -->
<!-- 在struts.xml中配置时,action的class使用application中的bean名 -->
<package name="default" namespace="/" extends="struts-default">
<action name="productAction_*" class="productAction" method="{1}">
<result name="success">/index.jsp</result>
</action>
</package>
在applicationContext.xml中,引用hibernate.cfg.xml文件
hibernate.cfg.xml中配置:
<session-factory>
<!-- 设置基本属性 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql:///spring01</property>
<property name="connection.username">root</property>
<property name="connection.password">1234</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 配置Hibernate使用c3p0连接池 -->
<property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<mapping resource="cn/xiaoge/domain/Product.hbm.xml" />
</session-factory>
在applictionContext.xml中进行配置:
<bean name="sf" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 相关事务配置后续添加 -->
方法二是直接在applicationContext中数据库配置相关信息
<!-- 配置连接池信息 -->
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///spring01"></property>
<property name="user" value="root"></property>
<property name="password" value="1234"></property>
</bean>
<!-- 配置Hibernate必备的sessionFactory -->
<bean name="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
<!-- 配置orm映射文件,切记value中配置的是包,不含文件名 -->
<property name="mappingDirectoryLocations"
value="classpath:cn/xiaoge/domain"></property>
</bean>
<!-- 配置hibernateTemplete(hibernate模板) -->
<bean name="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置事务管理器(事务管理的核心) -->
<bean name="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置通知advice -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" isolation="DEFAULT" read-only="false"/>
</tx:attributes>
</tx:advice>
<!-- 配置织入-->
<aop:config>
<aop:pointcut expression="execution(* cn.xiaoge.service..*ServiceImpl.*(..))" id="pc"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/>
</aop:config>
备注:其他业务类及持久类的配置省略,根据需求自行添加