一、导依赖包
二、项目的目录结构
三、web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee "
version="3.1">
<!--懒加载过滤器,解决懒加载问题-->
<filter>
<filter-name>openSession</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSession</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!-- struts2的前端控制器 -->
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- spring 创建监听器 -->
<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>
</web-app>
四、applicationContext.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:contex="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
">
<!-- 打开注解扫描开关 -->
<contex:component-scan base-package="com.pri"/>
<!-- 以下是属于hibernate的配置 -->
<bean>
<property value="com.mysql.jdbc.Driver"/>
<property value="jdbc:mysql:///ssh_demo1?useSSL=false"/>
<property value="root"/>
<property value=""/>
</bean>
<bean>
<!--1、核心配置-->
<property ref="dataSource"/>
<!-- 2、可选配置-->
<property>
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 3、扫描映射文件 -->
<property value="com.pri.domain"></property>
</bean>
<!--开启事务控制-->
<bean>
<property ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager= "transactionManager"/>
</beans>
五、log4j.properties配置