Spring常用的配置
来源:互联网 发布:js购物车功能的实现 编辑:程序博客网 时间:2024/05/01 06:03
<?xml version="1.0" encoding="UTF-8"?>
<beans 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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/> <!-- 打开注解配置 -->
<context:component-scan base-package="com.tr.itcase"/> <!-- 扫面类 -->
<context:property-placeholder location="classpath:jdbc.properties" /> <!-- 读取文件配置 -->
<aop:aspectj-autoproxy /> <!-- 打开切面配置 -->
<bean id="springProxy" class="com.tr.itcase.aop.SpringProxyXML" />
<bean id="personImpl" class="com.tr.itcase.impl.PersonImpl">
<property name="dataSource" ref="dataSource" /> <!-- 为属性注入 -->
</bean>
<aop:config>
<aop:aspect id="asp" ref="springProxy"> <!-- 定义切面类 -->
<aop:pointcut expression="execution (* com.tr.itcase.impl..*.*(..))"
id="myCut" /> <!-- 定义切入点 -->
<!--
<aop:pointcut expression="execution (* com.tr.itcase.impl..*.*(..))"
id="myCut" /> 拦截包下的所有的方法 <aop:pointcut expression="execution (*
com.tr.itcase.impl.*.*(java.lang.String,..))" id="myCut" />
拦截包下的方法第一个参数为String类型 <aop:pointcut expression="execution (!void
com.tr.itcase.impl.*.*(..))" id="myCut" /> 拦截包下的方法返回非void类型的方法
-->
<aop:before method="beforeMethod" pointcut-ref="myCut" /> <!-- 定义通知 -->
<aop:after method="afterMethod" pointcut-ref="myCut" /> <!-- 最终通知 -->
<aop:after-returning method="methodAfter"
pointcut-ref="myCut" /> <!-- 后置通知 -->
<aop:around method="doAround" pointcut-ref="myCut" />
</aop:aspect>
</aop:config>
<!-- jdbc操作 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!-- 定义数据源 -->
<property name="driverClassName" value="${driverClassName}">
</property>
<property name="url" value="${url}">
</property>
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxIdle" value="${maxIdle}" />
<property name="minIdle" value="${minIdle}" />
</bean>
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- jdbc事物管理类 -->
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 把dataSource注入到spring事物管理类 -->
<tx:annotation-driven transaction-manager="txManager" /> <!-- 使用注解事物管理,把事物管理类注入 -->
<aop:config>
<aop:pointcut expression="exectution (* com.tr.itcase.impl.*(..))" id="txPointcut"/> <!-- 为事物定义切面 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/> <!-- 把事物织入切面 -->
</aop:config>
<!-- 使用xml定义事物的传播路径 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/> <!-- 拦截所有方法以get开头的 并且是只读的 不开启事物 -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
</beans>
- Spring常用的配置
- 【Spring】Spring常用配置-Bean的Scope
- 【Spring】Spring配置数据源的常用方式
- Spring的applicationContext.xml常用配置
- Spring常用的web.xml文件配置
- spring中bean配置的常用方式
- Spring连接池的常用配置
- Spring中常用的连接池配置
- spring 常用的数据库链接配置
- Spring Boot 一些常用的pom配置
- 【Spring】Spring常用配置-Bean的初始化和销毁(生命周期)
- 【Spring】Spring常用配置-Profile
- spring常用的mvc配置和定时器的配置
- spring常用的mvc配置和定时器的配置
- ssh_1 常用spring配置
- 常用Spring配置项
- Spring 常用配置小结
- spring常用配置
- memcached-client for java 改进,更好支持tokyo
- android selector的使用
- tomcat中应用部署问题
- C语言操作mysql数据 常用函数
- Secret sharing密钥分散
- Spring常用的配置
- 解决ubuntu无法看到windows的共享文件夹
- 目前福岛高水平辐射量可能由2号反应堆释放
- 浙江招“黑客级”网络安全公务员
- 思路集锦
- 日本尝试冷却福岛电站5号6号反应堆乏燃料池
- C语言中fopen的一般用法
- 2010年度内资(私营)企业年检须知
- 第一核电站5号6号机组乏燃料池水温上升