导入所需要的jar包: xwork-core-2.2.1.jarxwork-core-2.2.1.jar struts2-spring-plugin-2.2.1.jarstruts2-spring-plugin-2.2.1.jar struts2-cor

来源:互联网 发布:淘宝卖图书 编辑:程序博客网 时间:2024/05/17 07:04
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  6.            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  7.            http://www.springframework.org/schema/context  
  8.            http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  9.            http://www.springframework.org/schema/aop  
  10.            http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  11.            http://www.springframework.org/schema/tx   
  12.            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  13.     <!-- 用注解方式注入bean,启动服务器时,spring会到com.yj查找所有带spring的注解(如:@Component),把他们注入到spring中 -->  
  14.     <context:annotation-config/>  
  15.     <context:component-scan base-package="com.yj"/>  
  16.     <!-- hibernate sessionFactory 创建 -->  
  17.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
  18.         <property name="packagesToScan">  
  19.             <list>  
  20.                 <value>com.yj.model</value>  
  21.             </list>  
  22.         </property>  
  23.         <property name="hibernateProperties">  
  24.             <props>  
  25.                 <prop key="hibernate.format_sql">true</prop>  
  26.                 <prop key="hibernate.hbm2ddl.auto">auto</prop>  
  27.                 <prop key="hibernate.show_sql">true</prop>  
  28.                 <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>  
  29.                 <!--指定Proxool的alias,必须与Proxool的配置文件中的alias一致-->      
  30.                 <prop key="hibernate.proxool.pool_alias">datasource</prop>    
  31.                 <!--指定Proxool配置文件-->     
  32.                 <prop key="hibernate.proxool.xml">proxool.xml</prop>    
  33.                 <prop key="hibernate.connection.provider_class">    
  34.                     org.hibernate.connection.ProxoolConnectionProvider    
  35.                 </prop>   
  36.             </props>  
  37.         </property>  
  38.     </bean>  
  39.      <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">  
  40.         <property name="sessionFactory" ref="sessionFactory"></property>  
  41.      </bean>       
  42.      <!-- 事物配置 -->  
  43.      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  44.         <property name="sessionFactory" ref="sessionFactory"></property>  
  45.      </bean>  
  46.      <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  47.         <tx:attributes>  
  48.             <tx:method name="find*" read-only="true"/>  
  49.             <tx:method name="add*" propagation="REQUIRED"/>  
  50.             <tx:method name="save*" propagation="REQUIRED"/>  
  51.         </tx:attributes>  
  52.      </tx:advice>  
  53.      <aop:config>  
  54.         <aop:pointcut expression="execution(public * com.yj.service..*.*(..))" id="myPointcut"/>  
  55.         <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut"/>  
  56.      </aop:config>  
  57.        
  58. </beans> 
原创粉丝点击