crud/main/resources/applicationContext.xml

128 lines
5.5 KiB
XML
Raw Normal View History

2023-05-24 15:00:58 +00:00
<?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.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--组件扫描-->
<context:component-scan base-package="com"></context:component-scan>
<!--1、加载jdbc.properties-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--2、配置数据源对象-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--spring整合mybatis-->
<!--配置sessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--加载mybatis核心配置文件-->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>
<!--扫描mapper所在包 为mapper创建实现类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mapper"></property>
</bean>
<!--<bean id="roleService" class="com.service.impl.RoleServiceImpl">
<property name="roleMapper" ref="roleMapper"></property>
</bean>
<bean id="userService" class="com.service.impl.UserServiceImpl">
<property name="roleMapper" ref="roleMapper"></property>
<property name="userMapper" ref="userMapper"></property>
</bean>-->
<!--
&lt;!&ndash;3、配置JdbcTemplate对象&ndash;&gt;
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
&lt;!&ndash;配置RoleService&ndash;&gt;
<bean id="roleService" class="com.service.impl.RoleServiceImpl">
<property name="roleDao" ref="roleDao"/>
</bean>
&lt;!&ndash;配置RoleDao&ndash;&gt;
<bean id="roleDao" class="com.dao.impl.RoleDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
&lt;!&ndash;配置UserService&ndash;&gt;
<bean id="userService" class="com.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"/>
<property name="roleDao" ref="roleDao"/>
</bean>
&lt;!&ndash;配置UserDao&ndash;&gt;
<bean id="userDao" class="com.dao.impl.UserDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>-->
<!--aop配置-->
<!--目标对象-->
<bean id="target" class="com.aop.target"></bean>
<!--切面对象-->
<bean id="MyAspect" class="com.aop.myAspect"></bean>
<!--织入-->
<!-- <aop:config>
&lt;!&ndash;声明切面&ndash;&gt;
<aop:aspect ref="MyAspect" >
&lt;!&ndash;切面:切点+通知&ndash;&gt;
&lt;!&ndash; <aop:before method="show1" pointcut="execution(public void com.aop.target.show())"></aop:before>
<aop:after-returning method="show2" pointcut="execution(* *.*.*.show())"></aop:after-returning>
<aop:around method="show3" pointcut="execution(* *.*.*.show(..))"></aop:around>&ndash;&gt;
&lt;!&ndash;抽取切点表达式&ndash;&gt;
<aop:pointcut id="pointcut" expression="execution(* *.*.*.show(..))"/>
<aop:before method="show1" pointcut-ref="pointcut"></aop:before>
<aop:after-returning method="show2" pointcut-ref="pointcut"></aop:after-returning>
<aop:around method="show3" pointcut-ref="pointcut"></aop:around>
</aop:aspect>
</aop:config>-->
<!--注解实现aop-->
<context:component-scan base-package="com.anno" ></context:component-scan>
<!--aop自动代理-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<!--配置平台事务管理器-->
<bean id="transaction" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--通知 事务的增强-->
<tx:advice id="advice" transaction-manager="transaction">
<!--设置事务的属性-->
<tx:attributes>
<tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="false"/>
<tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="false"/>
<tx:method name="save" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="false"/>
</tx:attributes>
</tx:advice>
<!--配置事务的织入-->
<aop:config>
<aop:advisor advice-ref="advice" pointcut="execution(* com.service.impl.*.*(..))"></aop:advisor>
</aop:config>
<!--注解配置平台事务-->
<!--配置注解驱动-->
<tx:annotation-driven transaction-manager="transaction"></tx:annotation-driven>
</beans>