1、Spring配置文件
<!--创建 hiber模板类 -->2、Struts配置文件
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate" autowire="byType">
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.DriverManagerDataSource">
<property name="user" value="root"></property>
<property name="password" value=""></property>
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost/item?characterEncoding=UTF-8"></property>
</bean>
<!-- 创建Sessio 工厂类 -->
<bean id="sessionfactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" >
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 创建实物管理对象 -->
<bean id="tx" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionfactory"> </property>
</bean>
<aop:config>
<aop:pointcut expression="execution(* com.third.service.impl.*.*(..))" id="pointcut"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
</aop:config>
<!-- 创建实物通知 -->
<tx:advice id="advice" transaction-manager="tx">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<?xml version="1.0" encoding="UTF-8" ?>3、Hibernate配置文件
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="struts" namespace="/" extends="struts-default">
<action name="" class="" method="">
<result name="success"></result>
</action>
</package>
</struts>
<hibernate-configuration>3、web配置文件
<session-factory name="configlocation">
<!-- 链接数据库 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/item?characterEncoding=UTF-8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- 更新数据库 -->
<property name="hbm2ddl.auto">update</property>
<!-- 显示sql语句 -->
<property name="show_sql">true</property>
<!-- sql语句规范化 -->
<property name="format_sql">true</property>
</session-factory>
</hibernate-configuration>
<!-- listener监听 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>