当前位置 : 主页 > 网页制作 > xml >

aplicationContext.xml的简单配置(纯为了防止自己忘记... )

来源:互联网 收集:自由互联 发布时间:2021-06-13
?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:tx="http://www.springframework

<?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:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<!--组件扫描,扫描需要的dao和service-->
<context:component-scan base-package="com.zn">
   <!--排除controller-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<!--加载jdbc.properties配置文件--><context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder><!--配置数据源信息--><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">    <property name="driverClass" value="${jdbc.driver}"></property>    <property name="jdbcUrl" value="${jdbc.url}"></property>    <property name="user" value="${jdbc.username}"></property>    <property name="password" value="${jdbc.password}"></property></bean><!--配置sessionFactory--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">    <property name="dataSource" ref="dataSource"></property>    <!--加载mybatis核心文件,如果spring将mybatis完全整合,即可以去除这一句-->    <property name="configLocation" value="classpath:mybatis.xml"></property></bean><!--扫描dao所在的包 为dao创建实现类--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">    <property name="basePackage" value="com.zn.dao"></property></bean><!--声明式事务控制--><!--平台事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">    <property name="dataSource" ref="dataSource"></property></bean><!--配置事务增强--><tx:advice id="txAdvice">    <tx:attributes>        <tx:method name="*"/>    </tx:attributes></tx:advice><!--事务的aop织入--><aop:config>    <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.zn.service.impl.*.*(..))"></aop:advisor></aop:config>
网友评论