Spring完整配置文件带注释(自动扫包)
2012-06-22 12:32
309 查看
<?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>
<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>
相关文章推荐
- Spring完整配置文件带注释(自动扫包)
- 在Web.xml中自动扫描Spring的配置文件及resource时classpath*:与classpath:的区别
- 扩展:Spring的PropertyPlaceholderConfigurer应用(自动获取配置文件的数据)
- Spring3 Mybatis3 freemarker 自动生成对应表的model、mapper、service、controller并自动修改mybatis配置文件
- [原创]java WEB学习笔记99:Spring学习---Spring Bean配置:自动装配,配置bean之间的关系(继承/依赖),bean的作用域(singleton,prototype,web环境作用域),使用外部属性文件
- spring配置mybatis自动扫描*mapper.java和*mapper.xml配置文件
- eclipse(xmlbuddy插件)为xml文件自动提示(同MyEclipse编辑XML的提示功能),以spring配置文件为例
- spring mvc 在Web.xml中自动扫描Spring的配置文件及resource时classpath*:与classpath:的区别
- SpringBoot 使用注解将配置文件自动映射到属性和实体类
- Spring4深入理解IOC&DI02----Bean配置--自动装配、bean之间的继承与依赖、使用外部属性文件
- 在Web.xml中自动扫描Spring的配置文件及resource时classpath*:与classpath:的区别
- Spring-Boot之基础 POM 文件和自动配置(maven)
- Spring Web项目spring配置文件随服务器启动时自动加载
- spring配置文件自动提示
- 构建springboot自动生成mapper文件和dao接口项目的步骤和配置
- spring-boot引入配置文件及排除自动配置类
- spring 配置文件的 完整xmlns
- 在编辑Spring的配置文件时的自动提示
- r.js 配置文件 example.build.js 不完整注释
- spring学习笔记(4)——配置文件配置bean自动装配