使用Maven构建SSM架构的JavaWeb项目的过程笔记(三):beans.xml

来源:互联网 发布:linux服务器安全 书籍 编辑:程序博客网 时间:2024/06/10 06:06

Maven项目下的src/main/resources/beans.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:p="http://www.springframework.org/schema/p"    xmlns:tx="http://www.springframework.org/schema/tx"    xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:aop="http://www.springframework.org/schema/aop"    xmlns:context="http://www.springframework.org/schema/context"    xsi:schemaLocation="    http://www.springframework.org/schema/tx     http://www.springframework.org/schema/tx/spring-tx-3.0.xsd    http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc-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/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-3.0.xsd    " default-autowire="byName">    <!-- 配置自动扫描 -->    <context:component-scan base-package="com.oecoo.gf"/>    <!-- 数据源 -->    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>        <property name="url" value="jdbc:mysql://127.0.0.1:3306/tj1018"/>        <property name="username" value="root"/>        <property name="password" value="root"/>    </bean>    <!-- Session工厂 -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>    </bean>    <!-- 扫描Mapper接口 -->    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <property name="basePackage" value="com.oecoo.gf.mapper"/>        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>    </bean>    <!-- 创建事务管理器 -->    <bean id="tm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="dataSource"/>    </bean>    <!-- 开启注解声明式事务 -->    <tx:annotation-driven transaction-manager="tm" proxy-target-class="true"/>    <!-- 开启SpringMVC注解 -->    <mvc:annotation-driven/>    <!-- 创建通知类对象 -->    <bean id="gfAdvice" class="com.oecoo.gf.advice.GfAdvice"/>    <!-- 配置切面 -->    <aop:config>        <!-- 关注点(方法) -->        <aop:pointcut expression="execution(public * com.oecoo.gf.controller.TbUsersController.*(..))"                                                             id="usersPoint"/>        <aop:advisor advice-ref="gfAdvice" pointcut-ref="usersPoint"/>    </aop:config>    <!-- 静态资源 -->    <mvc:resources location="/js/" mapping="/js/**" />    <mvc:resources location="/images/" mapping="/images/**" />    <mvc:resources location="/lib/" mapping="/lib/**" />    <mvc:resources location="/static/" mapping="/static/**" />    <mvc:resources location="/temp/" mapping="/temp/**" />    <mvc:resources location="/page/" mapping="/page/**"/></beans>