Maven+SSH+Easyui项目配置
一:建一个Maven项目
hibernate核心包
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
二:配置hibernate.cfg.cml配置文件
三:配置applicationContent.public.xml(其中关联了hibernate和spring)
1:加入spring-content抵赖
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
2.配置数据源(数据库连接池c3p0)
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${pass}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="initialPoolSize" value="${initPoolSize}"></property>
<property name="maxPoolSize" value="${maxPoolSize}"></property>
</bean>
3.配置sessionFactory 导入 dataSource 并且加载hibernate.cfg.cml配置文件并且加载映射文件
(配置sessionFactory文件之前记得添加spring-orm依赖)
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 导入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 加载hibernate 配置文件 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 加载映射文件 -->
<property name="mappingLocations" value="classpath:com/zking/Entity/*.hbm.xml"></property>
</bean>
4.配置事物管理器
(记得添加spring-aspects依赖)
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
!-- 配置事物管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
5配置事物的属性
<-- 配置事物的属性 -->
<tx:advice id="myadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
6.配置事物的切点
<!-- 配置事物切点 -->
<aop:config>
<aop:pointcut expression="execution(* com.zking.dao.*.*(..))" id="Mypoint"/>
<aop:advisor advice-ref="myadvice" pointcut-ref="Mypoint"/>
</aop:config>
四:配置WEB-INF/Web.xml(配置Struts 的 filer 过滤器拦截所有的请求 并且 在web 启动时 加载 applicationContent_public.xml文件)
1.配置Struts filter
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
2配置在web启动时加载applicationContent_public.xml
<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>
五:最后配置Struts.xml 配置action