spring 配置

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.  xmlns="http://www.springframework.org/schema/beans"  
  4.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.  xmlns:context="http://www.springframework.org/schema/context"  
  6.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  7.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  8.                     http://www.springframework.org/schema/context  
  9.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  10.                     ">  
  11.   
  12. <context:component-scan base-package="com.persia">  
  13. <!-- 开启组件扫描 -->  
  14. </context:component-scan>  
  15.   
  16. <context:annotation-config>  
  17. <!--开启注解处理器-->  
  18. </context:annotation-config>  
  19.   
  20. <!-- 使用注解,省去了propertity的xml配置,减少xml文件大小 -->  
  21. <bean id="personServiceAnno" class="com.persia.PersonServiceAnnotation"></bean>  
  22. <bean id="personDaoBeanAnno" class="com.persia.PersonDaoBean"></bean>  
  23. <bean id="personDaoBeanAnno2" class="com.persia.PersonDaoBean"></bean>  
  24.   
  25. <!-- 自动注解 -->  
  26. <bean id="personServiceAutoInject" class="com.persia.PersonServiceAutoInject" autowire="byName"></bean>  
  27.   
  28.   
  29. <bean id="personService" class="com.persia.PersonServiceBean">  
  30. <!-- 由spring容器去创建和维护,我们只要获取就可以了 -->  
  31. </bean>  
  32.   
  33. <bean id="personService2" class="com.persia.PersonServiceBeanFactory" factory-method="createInstance" lazy-init="true"   
  34.       init-method="init"  destroy-method="destory">  
  35. <!-- 静态工厂获取bean -->  
  36. </bean>  
  37.   
  38. <bean id="fac" class="com.persia.PersonServiceBeanInsFactory"></bean>  
  39. <bean id="personService3" factory-bean="fac" factory-method="createInstance" scope="prototype">  
  40. <!-- 实例工厂获取bean,先实例化工厂再实例化bean-->  
  41. </bean>  
  42.   
  43.   
  44. <!-- ref方式注入属性 -->  
  45. <bean id="personDao" class="com.persia.PersonDaoBean"></bean>  
  46. <bean id="personService4" class="com.persia.PersonServiceBean">  
  47.   <property name="personDao" ref="personDao"></property>  
  48. </bean>  
  49.   
  50. <!-- 内部bean方式注入 -->  
  51. <bean id="personService5" class="com.persia.PersonServiceBean">  
  52.   <property name="personDao">  
  53.      <bean class="com.persia.PersonDaoBean"></bean>  
  54.   </property>  
  55.   <property name="name" value="persia"></property>  
  56.   <property name="age" value="21"></property>  
  57.     
  58.   <property name="sets">  
  59.     <!-- 集合的注入 -->  
  60.      <set>  
  61.        <value>第一个</value>  
  62.        <value>第二个</value>  
  63.        <value>第三个</value>  
  64.      </set>  
  65.   </property>  
  66.     
  67.   <property name="lists">  
  68.     <!-- 集合的注入 -->  
  69.     <list>  
  70.         <value>第一个l</value>  
  71.        <value>第二个l</value>  
  72.        <value>第三个l</value>  
  73.     </list>  
  74.       
  75.   </property>  
  76.     
  77.   <property name="properties">  
  78.     <props>  
  79.       <prop key="key1">value1</prop>  
  80.       <prop key="key2">value2</prop>  
  81.       <prop key="key3">value3</prop>  
  82.     </props>  
  83.   </property>  
  84.     
  85.   <property name="map">  
  86.    <map>  
  87.       <entry key="key1" value="value-1"></entry>  
  88.       <entry key="key2" value="value-2"></entry>  
  89.       <entry key="key3" value="value-3"></entry>  
  90.    </map>  
  91.   </property>  
  92. </bean>  
  93.   
  94. <bean id="personService6" class="com.persia.PersonServiceBean">  
  95.    <constructor-arg index="0" value="构造注入的name" ></constructor-arg>  
  96.    <!-- 基本类型可以不写type -->  
  97.    <constructor-arg index="1" type="com.persia.IDaoBean" ref="personDao">  
  98.    </constructor-arg>   
  99. </bean>  
  100.   
  101. </beans>  


2.开启AOP:

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.  xmlns="http://www.springframework.org/schema/beans"  
  4.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.  xmlns:context="http://www.springframework.org/schema/context"  
  6.  xmlns:aop="http://www.springframework.org/schema/aop"  
  7.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  8.                     http://www.springframework.org/schema/beans/spring-beans-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/context  
  12.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  13.                    ">  
  14.   
  15. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
  16. <bean id="myInterceptor" class="com.persia.service.MyInterceptor"></bean>  
  17. <bean id="personServiceImpl" class="com.persia.service.impl.PersonServiceImpl"></bean>  
  18. </beans>AOP的xml版本<?xml version="1.0" encoding="UTF-8"?>  
  19. <beans  
  20.  xmlns="http://www.springframework.org/schema/beans"  
  21.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  22.  xmlns:context="http://www.springframework.org/schema/context"  
  23.  xmlns:aop="http://www.springframework.org/schema/aop"  
  24.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  25.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  26.                      http://www.springframework.org/schema/aop  
  27.                     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  28.                     http://www.springframework.org/schema/context  
  29.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  30.                    ">  
  31.   
  32. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
  33.   
  34. <bean id="personService" class="com.persia.service.impl.PersonServiceImpl"></bean>  
  35. <bean id="aspectBean" class="com.persia.service.MyInterceptor"></bean>  
  36.   
  37. <aop:config>  
  38.  <aop:aspect id="myaop" ref="aspectBean">  
  39.  <aop:pointcut id="mycut" expression="execution(* com.persia.service.impl.PersonServiceImpl.*(..))"/>  
  40.  <aop:pointcut id="argcut" expression="execution(* com.persia.service.impl.PersonServiceImpl.*(..)) and args(name)"/>    
  41.  <aop:before pointcut-ref="mycut" method="doAccessCheck"  />  
  42.  <aop:after-returning pointcut-ref="mycut" method="doAfterReturning"/>  
  43.    <aop:after-throwing pointcut-ref="mycut" method="doThrowing"/>  
  44.    <aop:after pointcut-ref="argcut" method="doAfter" arg-names="name"/>  
  45.  <aop:around pointcut-ref="mycut" method="arround"/>  
  46.  </aop:aspect>  
  47.     
  48. </aop:config>  
  49.   
  50. </beans>  


3.开启事务和注解:

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.  xmlns="http://www.springframework.org/schema/beans"  
  4.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.  xmlns:context="http://www.springframework.org/schema/context"  
  6.  xmlns:aop="http://www.springframework.org/schema/aop"  
  7.  xmlns:tx="http://www.springframework.org/schema/tx"   
  8.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  9.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  10.                     http://www.springframework.org/schema/context  
  11.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  12.                     http://www.springframework.org/schema/aop  
  13.                     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  14.                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   
  15.                    ">  
  16.   
  17. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
  18.                      
  19. <!-- 配置数据源 -->     
  20.   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">     
  21.     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>     
  22.     <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"/>     
  23.     <property name="username" value="root"/>     
  24.     <property name="password" value=""/>     
  25.      <!-- 连接池启动时的初始值 -->     
  26.      <property name="initialSize" value="1"/>     
  27.      <!-- 连接池的最大值 -->     
  28.      <property name="maxActive" value="500"/>     
  29.      <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->     
  30.      <property name="maxIdle" value="2"/>     
  31.      <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->     
  32.      <property name="minIdle" value="1"/>     
  33.   </bean>    
  34.      
  35.   <!-- 配置事务管理器-->     
  36.  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">     
  37.     <property name="dataSource" ref="dataSource"/>     
  38.   </bean>    
  39.   <!-- 配置业务bean -->  
  40.     <bean id="personService" class="com.persia.service.impl.PersonServiceImpl">  
  41.     <property name="ds" ref="dataSource"></property>  
  42.   </bean>  
  43.      
  44.   <!-- 采用@Transactional注解方式来使用事务 -->     
  45.   <tx:annotation-driven transaction-manager="txManager"/>   
  46.   
  47.   
  48. </beans>  
  49.   
  50. XML版本:  
  51.   
  52. <?xml version="1.0" encoding="UTF-8"?>  
  53. <beans  
  54.  xmlns="http://www.springframework.org/schema/beans"  
  55.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  56.  xmlns:context="http://www.springframework.org/schema/context"  
  57.  xmlns:aop="http://www.springframework.org/schema/aop"  
  58.  xmlns:tx="http://www.springframework.org/schema/tx"   
  59.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  60.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  61.                     http://www.springframework.org/schema/context  
  62.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  63.                     http://www.springframework.org/schema/aop  
  64.                     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  65.                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   
  66.                    ">  
  67.   
  68. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>  
  69.                      
  70. <!-- 配置数据源 -->     
  71.   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">     
  72.     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>     
  73.     <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"/>     
  74.     <property name="username" value="root"/>     
  75.     <property name="password" value=""/>     
  76.      <!-- 连接池启动时的初始值 -->     
  77.      <property name="initialSize" value="1"/>     
  78.      <!-- 连接池的最大值 -->     
  79.      <property name="maxActive" value="500"/>     
  80.      <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->     
  81.      <property name="maxIdle" value="2"/>     
  82.      <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->     
  83.      <property name="minIdle" value="1"/>     
  84.   </bean>    
  85.      
  86. <!-- 配置事务管理器 -->  
  87.  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">     
  88.     <property name="dataSource" ref="dataSource"/>     
  89.   </bean>    
  90.   <!-- 配置业务bean -->  
  91.    <bean id="personService" class="com.persia.service.impl.PersonServiceImpl">  
  92.     <property name="ds" ref="dataSource"></property>  
  93.   </bean>  
  94.     
  95.     
  96.     <!-- 使用XML来使用事务管理-->    
  97. <aop:config>    
  98.     <!-- 配置一个切面,和需要拦截的类和方法 -->     
  99.     <aop:pointcut id="transactionPointcut" expression="execution(* com.persia.service..*.*(..))"/>    
  100.     <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>    
  101. </aop:config>   
  102. <!-- 配置一个事务通知 -->      
  103. <tx:advice id="txAdvice" transaction-manager="txManager">    
  104.       <tx:attributes>   
  105.       <!-- 方法以get开头的,不使用事务 -->   
  106.         <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/>   
  107.       <!-- 其他方法以默认事务进行 -->   
  108.         <tx:method name="*"/>    
  109.       </tx:attributes>    
  110. </tx:advice>    
  111.      
  112.     
  113. </beans>  


4.SSH:

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.  xmlns="http://www.springframework.org/schema/beans"  
  4.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.  xmlns:context="http://www.springframework.org/schema/context"  
  6.  xmlns:aop="http://www.springframework.org/schema/aop"  
  7.  xmlns:tx="http://www.springframework.org/schema/tx"   
  8.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  9.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  10.                     http://www.springframework.org/schema/context  
  11.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  12.                     http://www.springframework.org/schema/aop  
  13.                     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  14.                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   
  15.                    ">  
  16.   
  17.   
  18.  <!-- 配置数据源 -->     
  19.   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">     
  20.     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>     
  21.     <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"/>     
  22.     <property name="username" value="root"/>     
  23.     <property name="password" value=""/>     
  24.      <!-- 连接池启动时的初始值 -->     
  25.      <property name="initialSize" value="1"/>     
  26.      <!-- 连接池的最大值 -->     
  27.      <property name="maxActive" value="500"/>     
  28.      <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->     
  29.      <property name="maxIdle" value="2"/>     
  30.      <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->     
  31.      <property name="minIdle" value="1"/>     
  32.   </bean>    
  33.     
  34.   <!-- 配置hibernate的sessionFactory -->  
  35. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  36.  <property name="dataSource"><ref bean="dataSource" /></property>  
  37.   <property name="mappingResources">  
  38.       <list>  
  39.         <value>com/persia/model/Person.hbm.xml</value>  
  40.       </list>  
  41.    </property>  
  42.      
  43.      <!-- 1.首先在sessionFactory里面配置以上3条设置 -->  
  44.         <!-- 2.然后得在类路径下面添加一个ehcache.xml的缓存配置文件 -->  
  45.         <!-- 3.最后在要使用缓存的实体bean的映射文件里面配置缓存设置 -->  
  46.              <!--使用二级缓存-->   
  47.              <!-- 不使用查询缓存,因为命中率不是很高 -->   
  48.              <!-- 使用Ehcache缓存产品 -->    
  49.   <property name="hibernateProperties">  
  50.       <value>  
  51.           hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
  52.           hibernate.hbm2ddl.auto=update  
  53.           hibernate.show_sql=false  
  54.           hibernate.format_sql=false  
  55.           hibernate.cache.use_second_level_cache=true  
  56.                 hibernate.cache.use_query_cache=false  
  57.              hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider  
  58.       </value>  
  59.       </property>  
  60. </bean>  
  61.   
  62. <!-- 配置Spring针对hibernate的事务管理器 -->  
  63. <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  64.     <property name="sessionFactory" ref="sessionFactory"/>  
  65. </bean>  
  66.   
  67. <!-- 配置使用注解的方式来使用事务 -->   
  68. <tx:annotation-driven transaction-manager="txManager"/>  
  69.   
  70. <!-- 使用手工配置的注解方式来注入bean -->  
  71. <context:annotation-config></context:annotation-config>  
  72.   
  73. <!--定义要注入的业务bean -->  
  74. <bean id="personService" class="com.persia.service.impl.PersonServiceImpl"></bean>  
  75.   
  76. <!--将Struts的action交给Spring容器来管理 -->  
  77. <bean name="/person/list" class="com.persia.struts.PersonListAction">  
  78. <!--1.这里要求name和struts-config里面的action的path名称一致,因为id不允许有特殊字符-->  
  79. <!--2.还得在Struts-config文件里面添加Spring的请求处理器,该处理器会根据action的path属性到Spring容器里面寻找这个bean,若找到了则用这个bean来处理用户的请求-->  
  80. <!--3.然后去掉action的type标签和值(可选),当Spring处理器找不到该bean时,才会使用Struts的action-->  
  81. <!--4.最后在action里面使用Spring的注入方式来注入业务bean-->  
  82. </bean>  
  83.   
  84. <bean name="/person/manage" class="com.persia.struts.PersonManageAction"></bean>  
  85. </beans>  
  86.   
  87. 5.SSH2:  
  88. <?xml version="1.0" encoding="UTF-8"?>  
  89. <beans  
  90.  xmlns="http://www.springframework.org/schema/beans"  
  91.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  92.  xmlns:context="http://www.springframework.org/schema/context"  
  93.  xmlns:aop="http://www.springframework.org/schema/aop"  
  94.  xmlns:tx="http://www.springframework.org/schema/tx"   
  95.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  96.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  97.                     http://www.springframework.org/schema/context  
  98.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  99.                     http://www.springframework.org/schema/aop  
  100.                     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  101.                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   
  102.                    ">  
  103.   
  104.   
  105.  <!-- 配置数据源 -->     
  106.   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">     
  107.     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>     
  108.     <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8"/>     
  109.     <property name="username" value="root"/>     
  110.     <property name="password" value=""/>     
  111.      <!-- 连接池启动时的初始值 -->     
  112.      <property name="initialSize" value="1"/>     
  113.      <!-- 连接池的最大值 -->     
  114.      <property name="maxActive" value="500"/>     
  115.      <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->     
  116.      <property name="maxIdle" value="2"/>     
  117.      <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->     
  118.      <property name="minIdle" value="1"/>     
  119.   </bean>    
  120.     
  121.   <!-- 配置hibernate的sessionFactory -->  
  122. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  123.  <property name="dataSource"><ref bean="dataSource" /></property>  
  124.   <property name="mappingResources">  
  125.       <list>  
  126.         <value>com/persia/model/Person.hbm.xml</value>  
  127.       </list>  
  128.    </property>  
  129.      
  130.      <!-- 1.首先在sessionFactory里面配置以上3条设置 -->  
  131.         <!-- 2.然后得在类路径下面添加一个ehcache.xml的缓存配置文件 -->  
  132.         <!-- 3.最后在要使用缓存的实体bean的映射文件里面配置缓存设置 -->  
  133.              <!--使用二级缓存-->   
  134.              <!-- 不使用查询缓存,因为命中率不是很高 -->   
  135.              <!-- 使用Ehcache缓存产品 -->    
  136.   <property name="hibernateProperties">  
  137.       <value>  
  138.           hibernate.dialect=org.hibernate.dialect.MySQL5Dialect  
  139.           hibernate.hbm2ddl.auto=update  
  140.           hibernate.show_sql=false  
  141.           hibernate.format_sql=false  
  142.           hibernate.cache.use_second_level_cache=true  
  143.                 hibernate.cache.use_query_cache=false  
  144.              hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider  
  145.       </value>  
  146.       </property>  
  147. </bean>  
  148.   
  149. <!-- 配置Spring针对hibernate的事务管理器 -->  
  150. <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  151.     <property name="sessionFactory" ref="sessionFactory"/>  
  152. </bean>  
  153.   
  154. <!-- 配置使用注解的方式来使用事务 -->   
  155. <tx:annotation-driven transaction-manager="txManager"/>  
  156.   
  157. <!-- 使用手工配置的注解方式来注入bean -->  
  158. <context:annotation-config></context:annotation-config>  
  159.   
  160. <!--定义要注入的业务bean -->  
  161. <bean id="personService" class="com.persia.service.impl.PersonServiceImpl"></bean>  
  162.   
  163. <!--注入Struts 2的action -->  
  164. <bean id="personList" class="com.persia.struts2.action.PersonListAction"></bean>  
  165. </beans>6.SSJ:  
  166. <?xml version="1.0" encoding="UTF-8"?>  
  167. <beans  
  168.  xmlns="http://www.springframework.org/schema/beans"  
  169.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  170.  xmlns:context="http://www.springframework.org/schema/context"  
  171.  xmlns:aop="http://www.springframework.org/schema/aop"  
  172.  xmlns:tx="http://www.springframework.org/schema/tx"   
  173.  xsi:schemaLocation="http://www.springframework.org/schema/beans   
  174.                     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  175.                     http://www.springframework.org/schema/context  
  176.                     http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  177.                     http://www.springframework.org/schema/aop  
  178.                     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  179.                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   
  180.                    ">  
  181.   
  182.   
  183. <!-- 使用手工配置的注解方式来注入bean -->  
  184. <context:annotation-config></context:annotation-config>  
  185.   
  186. <!-- 1.配置Spring集成JPA -->  
  187. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">  
  188.       <property name="persistenceUnitName" value="SpringJPAPU"/>  
  189. </bean>  
  190.   
  191. <!--2.配置Spring针对JPA的事务 -->  
  192.     <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">  
  193.      <property name="entityManagerFactory" ref="entityManagerFactory"/>  
  194. </bean>  
  195.   
  196. <!--3.开启事务注解 -->  
  197. <tx:annotation-driven transaction-manager="txManager"/>  
  198.     
  199. <!--以上3个Spring集成JPA的配置,在web项目先添加Spring支持,后添加JPA支持时会自动生成 -->  
  200.   
  201. <!-- 配置业务bean -->  
  202. <bean id="personService" class="com.persia.service.impl.PersonServiceImpl"></bean>  
  203.   
  204. <!-- 配置Struts的action -->  
  205. <bean name="/person/list" class="com.persia.struts.PersonListAction"/>  
  206. <bean name="/person/manage" class="com.persia.struts.PersonManageAction"/>  
  207. </beans>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值