您的位置:首页 > 编程语言 > Java开发

Spring完整配置文件带注释(自动扫包)

2013-12-24 13:15 316 查看
<?xml version="1.0" encoding="UTF-8"?>
<beans
default-autowire="byName"
default-lazy-init="true"
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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
">

<!-- 开启注解配置 -->
<context:annotation-config />

<!-- 对指定的包进行组件扫描 -->
<context:component-scan base-package="com.lun" />

<!--链接数据库 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"></property>
<property name="username" value="lun"></property>
<property name="password" value="123"></property>
</bean>

<!-- 配置hibernate的sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<!-- 数据库方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<!-- 在控制台打印执行的sql语句 -->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<!-- 加载所有的实体配置文件 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/lun/entity</value>
</list>
</property>
</bean>

<!-- 事务处理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 事务通知配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="select*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="save*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="add*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="update*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="del*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="*" rollback-for="Exception" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>

<!-- 事务切面配置 -->
<aop:config>
<aop:pointcut expression="execution(* com.lun.biz.*.*(..))" id="transactionPointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut" />
</aop:config>

<!-- 注入jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>

<!-- 注入hibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐