首页 > 其他 > 详细

beans.xml

时间:2017-01-06 12:18:42      阅读:140      评论:0      收藏:0      [点我收藏+]
 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"
 4         xmlns:context="http://www.springframework.org/schema/context"
 5          xmlns:aop="http://www.springframework.org/schema/aop"
 6         xmlns:tx="http://www.springframework.org/schema/tx"
 7         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 8                 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
 9                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
10                 http://www.springframework.org/schema/aop
11                 http://www.springframework.org/schema/aop/spring-aop.xsd" >
12             <!-- 打开注解注入 -->
13             <context:annotation-config/>
14             <context:component-scan base-package="com.hkwy" />
15             <!-- 添加AOP annotation支持 -->
16             <aop:aspectj-autoproxy/>
17             <!-- 配置数据源 -->
18             <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
19             <!-- 基本参数 -->
20             <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
21             <property name="url" value="jdbc:mysql://localhost:3306/spring1"></property>
22             <property name="username" value="root"></property>
23             <property name="password" value="root"></property>
24             <!--配置连接池的参数  -->
25             <property name="initialSize" value="1"></property>
26             <!-- 连接池的最大数量 -->
27             <property name="maxActive" value="500"></property>
28             <!-- 空闲时  连接数降低到最小值 -->
29             <property name="maxIdle" value="2"></property>
30             <!-- 空闲时连接池的最小值 -->
31             <property name="minIdle" value="1"></property>
32             <!-- 最大等待时间 -->
33             <property name="maxWait" value="1000"></property>
34             </bean>
35         <!--配置hibernate SessionFactory  annotation方式  -->
36         <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
37             <!-- 将数据源配置进来 -->
38             <property name="dataSource" ref="dataSource"></property>
39             <!--对应的实体类,只需要指定包  -->
40             <property name="packagesToScan">
41                 <value>com.hkwy.entity</value>
42             </property>
43             <!-- 配置hibernate其他参数 -->
44             <property name="hibernateProperties">
45                 <props>
46                     <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
47                     <prop key="hibernate.show_sql">true</prop>
48                     <prop key="hibernate.format_sql">true</prop>
49                     <prop key="hibernate.hbm2ddl.auto">update</prop>
50                 </props>
51             </property>
52         </bean>
53         <!--将hibernate交给Spring管理其事务  -->
54         <!--配置事务管理器  -->
55         <bean id="txmanager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
56             <property name="sessionFactory" ref="sessionFactory"></property>
57         </bean>
58         <!--配置Spring的AOP 来管理事务  -->
59         <aop:config>
60             <!-- 配置需要管理的dao -->
61             <aop:pointcut expression="execution (* com.hkwy.dao.*.*(..))" id="aoph"/>
62             <!--通过advisor来确定具体要加入事务控制的方法  -->
63             <aop:advisor advice-ref="txadvice" pointcut-ref="aoph"/>
64         </aop:config>
65         <!-- 配置advice 来确定哪些数据操作需要加入到事务控制 -->
66         <tx:advice id="txadvice" transaction-manager="txmanager">
67             <tx:attributes>
68                 <tx:method name="*" propagation="REQUIRED"/>
69             </tx:attributes>
70         </tx:advice>
71             
72 </beans> 

 

beans.xml

原文:http://www.cnblogs.com/ryy1210/p/6255648.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!