`

struts2+spring+hibernate配置文件方式整合

阅读更多
大家互相学习,有什么不妥的地方希望指正



<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">


<bean id="sessionFactory"
	class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
	<property name="configLocation"
		value="classpath:hibernate.cfg.xml">
	</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 <property name="sessionFactory">
  <ref local="sessionFactory"/>
 </property>
</bean>
<!-- 配置事务特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
    <tx:method name="save*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <tx:method name="*" read-only="false"/>
  </tx:attributes>
</tx:advice>
<!-- 声明哪些包使用事务 -->
<aop:config >
<aop:pointcut expression="execution(* com.acca.service.*.*(..))" id="serviceManager"/>
  <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceManager"/>
</aop:config>
</beans>
 
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

	<session-factory>
		<property name="dialect">
			org.hibernate.dialect.MySQLDialect
	</property>
		<property name="connection.url">
			jdbc:mysql://localhost:3306/hibernate?useUnicode=true&amp;characterEncoding=UTF8
	</property>
		<property name="connection.username">root</property>
		<property name="connection.password">root</property>
		<property name="connection.driver_class">
			com.mysql.jdbc.Driver
	</property>
		<property name="myeclipse.connection.profile">mysql</property>
		<property name="show_sql">true</property>
		<property name="hbm2ddl.auto">update</property>//表示数据库中如果没有对应的表舅创建,如果存在则更新
		<mapping resource="com/acca/domain/User.hbm.xml" />//表示要引入的实体配置文件
		<mapping resource="com/acca/domain/Role.hbm.xml" />
		<mapping resource="com/acca/domain/UserRole.hbm.xml" />
	    <mapping resource="com/acca/domain/Permission.hbm.xml" />
	    <mapping resource="com/acca/domain/Acl.hbm.xml" />
	</session-factory>

</hibernate-configuration>
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>log4j</param-name>
    <param-value>classpath:WEB-INF/classes/log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/applicationContext*.xml</param-value>
  </context-param>
  <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>
</web-app>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics