spring xml配置相关

 

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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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">
    



    
    <aop:aspectj-autoproxy/>
    
    <context:component-scan base-package="com.csh.testcomponent"/>
    
    <context:property-placeholder location="jdbc.properties"/>
    
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}">property>
        <property name="url" value="${jdbc.url}">property>
        <property name="username" value="${jdbc.username}">property>
        <property name="password" value="${jdbc.password}">property>

    bean>
    
    
    
    <bean id="student" class="com.csh.pojo.Student">
        <property name="studentId" value="1001"/>
        <property name="studentName" value="Tom2015"/>
        <property name="age" value="18"/>
    bean>













    <bean id="teacher02" class="com.csh.pojo.Teacher">
        <property name="tid" value="1111"/>
        <property name="tname" value="玉兔"/>
        <property name="students">
            <list>
                <value>sksjfksjvalue>
                <value>看到附近value>
                <value>士大夫value>
                <value>OK见效快value>
            list>
        property>
    bean>
beans>

 

properties:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=root

 



aop:
xml version="1.0" encoding="UTF-8"?>

-<beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans">

<context:component-scan base-package="com.atguigu.spring.aopxml"/>


-<aop:config>


-<aop:aspect ref="myLogger">

<aop:pointcut id="cut" expression="execution(* com.atguigu.spring.aopxml.*.*(..))"/>




<aop:before pointcut-ref="cut" method="before"/>

aop:aspect>

aop:config>

beans>

 

添加事务:

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.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:component-scan base-package="com.atguigu.book_xml">context:component-scan>
    
    
    <context:property-placeholder location="db.properties"/>

    
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}">property>
        <property name="url" value="${jdbc.url}">property>
        <property name="username" value="${jdbc.username}">property>
        <property name="password" value="${jdbc.password}">property>
    bean>

    
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource">property>
    bean>
    
    
    <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource">property>
    bean>
    
    
    <tx:advice id="tx" transaction-manager="dataSourceTransactionManager">
        <tx:attributes>
            
            <tx:method name="buyBook"/>
            <tx:method name="checkOut"/>
            
            
            <tx:method name="select*" read-only="true"/>
            <tx:method name="insert*"/>
            <tx:method name="update*"/>
            <tx:method name="delete*"/>
            
            <tx:method name="*"/>
            
        tx:attributes>
    tx:advice>

    
    <aop:config>
        <aop:pointcut expression="execution(* com.atguigu.book_xml.service.impl.*.*(..))" id="pointCut"/>
        <aop:advisor advice-ref="tx" pointcut-ref="pointCut"/>
    aop:config>
    
beans>

 

你可能感兴趣的:(spring xml配置相关)