Spring applicatoincontest.xml 配置

来源:互联网 发布:淘宝刷好评多少钱一个 编辑:程序博客网 时间:2024/06/08 19:38

spring配置:

<?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: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-4.0.xsd             http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-4.0.xsd            http://www.springframework.org/schema/aop             http://www.springframework.org/schema/aop/spring-aop-4.0.xsd            http://www.springframework.org/schema/tx             http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">    <!-- 开启注解处理器 -->    <context:annotation-config />    <!-- 开户组件自动扫描 扫描 service,dao -->    <context:component-scan        base-package="com.duanrong.drproject.business.*.service, com.duanrong.drproject.business.*.dao" />    <!-- 开启基于@AspectJ切面的注解处理器 -->    <aop:aspectj-autoproxy />    <!-- 由于class属性指定的类的默认构造方法创建一个单实例bean,名称由id属性指定 -->    <bean id="Bean的实例名称" class="Bean类全名" />    <!-- scope属性为prototype时表示每次生成一个新的实例,即原型模式 -->    <bean id="Bean的实例名称" class="Bean类全名" scope="prototype" />    <!--init-method属性指定对象实例化后要调用的初始方法;        destroy-method属性指定对象销毁时要调用的方法-->    <bean id="Bean的实例名称" class="Bean类全名" init-method="初始化时调用的方法名"        destroy-method="对象销毁时调用的方法名" />    <!-- property标签用于对bean实例中的属性进行赋值,对于基本类型的属性值可以直接指定;而ref则是对其它bean实例的引用 -->    <bean id="Bean的实例名称" class="Bean类全名">        <property name="Bean类中的属性名称" ref="要引用的bean名称"/>        <property name="Bean类中的属性名称" value="直接指定的属性值"></property>        <property name="Bean类中的属性名称">            <bean class="bean类全名"></bean> <!-- 创建一个内部匿名bean实例赋值给指定的属性,该匿名bean实例无法被外界访问 -->        </property>        <!-- set标签用于创建一个set类型实例赋值给set类型的属性,set实例中的元素通过value或ref子标签指定。对于基本        类型的元素可由value标签生成;如果需要引用其它bean实例做为set元素的话可由ref标签指定 -->        <property name="Bean类中set类型的属性名称">            <set>                <value>set中的元素</value>                <ref bean="要引用的bean名称"/>            </set>        </property>        <!--list标签用于创建一个list类型实例赋值给List类型的属性,list实例中的元素通过value或ref子标签指定。对于        基本类型的元素可由value标签生成;如果需要引用其它bean实例做set元素的话可以ref标签指定  -->        <property name="Bean类中List类型的属性名称">            <list>                <value>list中的元素</value>                <ref bean="要引用的bean名称"/>            </list>        </property>        <!--map标签用于创建一个map类型实例赋值给map类型的属性,map实例中的元素通过entry标签指定,map元素的key由entry标签的        key属性直接指定,值由于value或ref子标签指定。对于        基本类型的元素可由value标签生成;如果需要引用其它bean实例做set元素的话可以ref标签指定   -->        <property name="bean类中的map类型属性">            <map>                <entry key="map元素的key">                    <value>map元素的value</value>                </entry>                <entry key="map元素的key">                    <ref bean="要引用的bean名称"/>                </entry>            </map>        </property>        <!-- 给propertiest类型的属性赋值 -->        <property name="bean类中properties类型属性名称">            <props>                <prop key="properties元素的key">properties元素的value</prop>            </props>        </property>        <!-- 给指定属性赋值为 null -->        <property name="bean类中要初始化为null的属性名称">            <null/>        </property>    </bean>     <!-- 通过传入相应的构造进行bean实例化,constructor-arg标签用于指定一个构造参数,其中index属性用于指定其为    第几个构造参数(从0开始 ),type属性申明构造参数的类型,构造参数的值由于value或ref属性指定 -->    <bean id="bean实例名称" class="bean类全名">        <constructor-arg index="从0开始的序号" type="构造参数的类型" value="构造参数的值"/>        <constructor-arg index="从0开始的序号" type="构造参数的类型" ref="要引用的bean名称"></constructor-arg>    </bean>    <aop:config>        <aop:aspect id="切面id" ref="要引用的切面实例名称">            <aop:pointcut expression="切入点正则表达示" id="切入点名称"/>            <aop:before method="切面类中用于前置通知的方法名称" pointcut-ref="切入点名称"/><aop:after-returning method="切面类中用于后置通知的方名称" pointcut-ref="切入点名称"/>            <aop:after-throwing method="切面类中用于异常通知的方法名称" pointcut-ref="切入点名称"/>            <aop:after method="切面类中用于最终通知的方法名称" pointcut-ref="切入点名称"/>            <aop:around method="切面类中用于环绕通知的方法名称" pointcut-ref="切入点名称"/>        </aop:aspect>    </aop:config>    <!-- 配置事物管理器 -->    <bean id="事物管理器实例名称" class="事物管理器类全名">        <property name="数据源属性名称" ref="要引用的数据源实例名称"></property>    </bean>    <!-- 配置一个事物通知 -->    <tx:advice id="事物通知名称" transaction-manager="事物管理器实例名称">        <tx:attributes>            <!-- 方法以get开头的不用事务 -->            <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/>            <!-- 其他方法以默认事务进行 -->            <tx:method name="*"/>        </tx:attributes>    </tx:advice>    <!-- 使用aop方法技术实现事务管理 -->    <aop:config>        <aop:pointcut expression="事物切入点正则表达式" id="事物切入点名称"/>        <aop:advisor advice-ref="事物通知名称" pointcut-ref="事物切入点名称"/>    </aop:config></beans>