spring中的配置文件applicationContext.xml示例

来源:互联网 发布:泡妞软件下载 编辑:程序博客网 时间:2024/04/27 13:39
<?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:util="http://www.springframework.org/schema/util"  
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

<bean id="dbcp"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="username" value="root">
    </property>
    <property name="password" value="1234">
    </property>
    <property name="driverClassName"
        value="com.mysql.jdbc.Driver">
    </property>
    <property name="url"
        value="jdbc:mysql:///cloud_note?useUnicode=true&amp;characterEncoding=utf8">
    </property>
</bean>

<bean id="ssf"
    class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dbcp">
    </property>
    <property name="mapperLocations"
        value="classpath:org/tarena/note/sql/*.xml">
    </property>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 扫描包下接口生成实现 -->
    <property name="basePackage"
        value="org.tarena.note.dao">
    </property>
    <!-- 自动注入ssf -->
</bean>

<!-- 开启组件扫描,扫描Service,Controller -->
<context:component-scan
    base-package="org.tarena.note"/>

<!-- handlermapping -->
<mvc:annotation-driven />

<!-- Spring注解事务配置 -->
<bean id="txManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dbcp">
    </property>
</bean>

<!-- @Transactional -->
<tx:annotation-driven
    transaction-manager="txManager"
    proxy-target-class="true"/>

<!-- AOP示例,XML配置版本 -->
<bean id="logBean"
    class="org.tarena.note.aopbean.LogServiceBean">
</bean>
<aop:config>
    <!-- 指定作用目标组件 -->
    <aop:pointcut id="servicePoint"
        expression="within(org.tarena.note.service..*)"/>
    <!-- 指定作用时机 -->
    <aop:aspect ref="logBean">
        <aop:before method="logService"
            pointcut-ref="servicePoint"/>
    </aop:aspect>
</aop:config>

<!-- **注解AOP配置*** -->
<!-- 通过组件扫描将LogControllerBean纳入spring容器 -->
<!-- -开启AOP注解,@Aspect,@Pointcut,@Before -->
<aop:aspectj-autoproxy
    proxy-target-class="true"/>

    
</beans>
0 0