阅读背景:

基于ssm框架的第二个项目配置文件的搭配

来源:互联网 

applicationContext.xml

<beans xmlns="https://www.springframework.org/schema/beans"
    xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="https://www.springframework.org/schema/mvc"
    xmlns:context="https://www.springframework.org/schema/context"
    xmlns:aop="https://www.springframework.org/schema/aop" 
    xmlns:tx="https://www.springframework.org/schema/tx"
    xsi:schemaLocation="https://www.springframework.org/schema/beans 
    https://www.springframework.org/schema/beans/spring-beans-4.3.xsd 
    https://www.springframework.org/schema/mvc 
    https://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 
    https://www.springframework.org/schema/context 
    https://www.springframework.org/schema/context/spring-context-4.3.xsd 
    https://www.springframework.org/schema/aop 
    https://www.springframework.org/schema/aop/spring-aop-4.3.xsd 
    https://www.springframework.org/schema/tx 
    https://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    <!--读取db.properties -->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 配置数据源 -->
    <bean id="dataSource" 
         class="org.apache.commons.dbcp2.BasicDataSource">
         <!--数据库驱动 -->
         <property name="driverClassName" value="${jdbc.driver}" />
         <!--连接数据库的url -->
         <property name="url" value="${jdbc.url}" />
         <!--连接数据库的用户名 -->
         <property name="username" value="${jdbc.username}" />
         <!--连接数据库的密码 -->
         <property name="password" value="${jdbc.password}" />
         <!--最大连接数 -->
         <property name="maxTotal" value="${jdbc.maxTotal}" />
         <!--最大空闲连接  -->
         <property name="maxIdle" value="${jdbc.maxIdle}" />
         <!--初始化连接数  -->
         <property name="initialSize" value="${jdbc.initialSize}" />
	</bean>
	<!-- 事务管理器 -->
	<bean id="transactionManager" class=
	"org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 数据源 -->
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 传播行为 -->
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="find*" propagation="SUPPORTS" 
                                           read-only="true" />
			<tx:method name="select*" propagation="SUPPORTS" 
                                           read-only="true" />
			<tx:method name="get*" propagation="SUPPORTS" 
                                           read-only="true" />
		</tx:attributes>
	</tx:advice>
	<!-- 切面 -->
	<aop:config>
		<aop:advisor advice-ref="txAdvice"
			 pointcut="execution(* com.core.service.*.*(..))" />
	</aop:config>
	<!-- 配置 MyBatis的工厂 -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 数据源 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 配置MyBatis的核心配置文件所在位置 -->
		<property name="configLocation" 
                     value="classpath:mybatis-config.xml" />
	</bean>
	<!-- 接口开发,扫描 com.core.dao包 ,写在此包下的接口即可被扫描到 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.core.dao" />
	</bean>
	<!-- 配置扫描@Service注解 -->
	<context:component-scan base-package="com.core.service"/>	
</beans>
<beans xmlns="https



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: