You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
8.5 KiB
XML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
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
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 开启注解扫描 -->
<mvc:annotation-driven/>
<!-- 注解扫面包路径 -->
<context:component-scan base-package="com.emr">
<!-- 制定扫包规则 ,不扫描@Controller注解的JAVA类 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!--启动任务定时器-->
<task:annotation-driven/>
<context:property-placeholder location="classpath:config/jdbc.properties" />
<!--配置数据源-->
<bean id="sqlServerDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.sqlserver.driver}"/> <!--数据库连接驱动-->
<property name="jdbcUrl" value="${jdbc.sqlserver.url}"/> <!--数据库地址-->
<property name="user" value="${jdbc.sqlserver.username}"/> <!--用户名-->
<property name="password" value="${jdbc.sqlserver.password}"/> <!--密码-->
<property name="maxPoolSize" value="40"/> <!-- 最大连接数-->
<property name="minPoolSize" value="1"/> <!--最小连接数-->
<property name="initialPoolSize" value="10"/> <!-- 初始化连接池内的数据库连接-->
<property name="maxIdleTime" value="20"/> <!--最大空闲时间-->
</bean>
<!-- mysql库连接池 -->
<bean id="mysqlDataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password driverClassName -->
<property name="driverClassName" value="${jdbc.mysql.driver}" />
<property name="url" value="${jdbc.mysql.url}" />
<property name="username" value="${jdbc.mysql.username}" />
<property name="password" value="${jdbc.mysql.password}" />
</bean>
<!-- 配置数据库切换类 -->
<bean id="dataSource" class="com.emr.DynamicDataSource">
<property name="targetDataSources">
<map>
<entry key="sqlServerDataSource" value-ref="sqlServerDataSource"/>
<entry key="mysqlDataSource" value-ref="mysqlDataSource"></entry>
</map>
</property>
<!-- 设置默认数据源 -->
<property name="defaultTargetDataSource" ref="sqlServerDataSource"/>
</bean>
<!-- ====================== 配置和MyBatis的整合 ======================== -->
<!--配置session工厂MyBatis的整合-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 指定mybatis全局配置文件的位置 -->
<property name="configLocation" value="classpath:config/mybatis-config.xml"></property>
<property name="dataSource" ref="dataSource"></property>
<!-- 指定mybatis,mapper文件的位置 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!-- mapper扫描 -->
<!-- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="com.emr.dao"></property>
</bean>-->
<!-- 配置扫描器将mybatis接口的实现加入到IOC容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<!-- 扫描所有的dao接口的实现加入到ioc容器 -->
<property name="basePackage" value="com.emr.dao"></property>
</bean>
<!-- 配置一个可以执行批量的sqlSession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
<constructor-arg name="executorType" value="BATCH"></constructor-arg>
</bean>
<!-- ====================== 事物管理器配置 ======================== -->
<!-- 事物管理器配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 开启基于注解的事务使用xml配置形式的事务必须主要的都是使用配置式 -->
<aop:config>
<!-- 切入表达式 -->
<aop:pointcut expression="execution(* com.emr.service..*(..))" id="txPoint"/>
<!-- 配置事务增强 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
</aop:config>
<!-- 配置事务增强 ,事务如何切入-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 所有方法都是事务方法 -->
<tx:attributes>
<tx:method name="*"/>
<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>
<!-- Spring配置文件的核心点数据源、与 mybatis的整合事务控制 -->
<!-- 事务扫描开始(开启@Tranctional) -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> -->
<!-- 使用annotation定义事务 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager"/> -->
<!-- 定义切面功能 -->
<!-- <aop:aspectj-autoproxy />-->
<!--<context:annotation-config></context:annotation-config>-->
<!-- 启用aop -->
<!--<aop:aspectj-autoproxy proxy-target-class="true"/>-->
<!-- 配置启用Shiro的注解功能 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true"></property>
</bean>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--<property name="realm" ref="userRealm"/>
<property name="sessionManager" ref="sessionManager"/>
<property name="rememberMeManager" ref="rememberMeManager"/>
<property name="cacheManager" ref="customShiroCacheManager"/>-->
</bean>
<!-- 上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"/>
<!-- 最大内存大小 -->
<property name="maxInMemorySize" value="10240"/>
<!-- 最大文件大小,-1为不限制大小 -->
<property name="maxUploadSize" value="-1"/>
</bean>
<!-- 自定义拦截器 -->
<!--<bean id="login" class="com.common.shiro.filter.LoginFilter"/>-->
<!-- Shiro生命周期处理器-->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
</beans>