application-mybatis配置文件 在配置以后需要将项目工程中的java EE6删除,否则会引发jar包冲突!
<?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:p="http://www.springframework.org/schema/p" 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-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="cn.dao,cn.service"/> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 指定JDBC驱动类 <property name="driverClassName" value="com.mysql.jdbc.Driver"> </property> 提供连接数据库的URL地址 <property name="url" value="jdbc:mysql://127.0.0.1:3306/fruit"> </property> 提供连接数据库的用户名和密码 <property name="username" value="root"></property> <property name="password" value="root"></property> </bean> --> <!-- 使用Druid测试连接数据库 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 url,user,password --> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/fruit" /> <property name="username" value="root" /> <property name="password" value="gnt1ixisO/lNy/bhP6CpxwbhWbvjpscWLWzoZl2xSTDUUgvb5xsz04kZKHoYDhgWQ7n1S3QDe/Wx9g1B67pshQ==" /> <!-- 数据库密码解密 --> <property name="filters" value="config"></property> <property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMFYvuXLffJtjLQ3vHZWh02/29zRsv/JAirOM6pWde6HMysg+VlqeX9HFsydUuwTZ6qpti3Wrd0+gfBha2m21yMCAwEAAQ==" /> <!-- 配置监控统计拦截的filters --> <!-- <property name="filters" value="stat" /> --> <!-- 配置初始化大小、最小、最大 --> <property name="maxActive" value="20" /> <property name="initialSize" value="1" /> <property name="minIdle" value="1" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="300000" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements" value="true" /> <property name="maxOpenPreparedStatements" value="20" /> </bean> <!-- sqlSessionFactory --> <!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 配置数据源 <property name="dataSource" ref="dataSource"/> mybatis全局文件,同意加载数据源 <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> --> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 自动扫描mapping.xml文件 --> <property name="mapperLocations" value="classpath:cn/dao/*.xml"></property> </bean> <!-- 配置SqlSessionTemplate --> <!-- <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg ref="sqlSessionFactory"></constructor-arg> </bean> --> <!-- 事务管理 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- AOP 事务处理 开始 --> <!-- <aop:aspectj-autoproxy /> <aop:config proxy-target-class="true"> <aop:pointcut expression="execution(* cn.service.impl..*(..))" id="transService"/> <aop:advisor pointcut-ref="transService" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" /> </tx:attributes> </tx:advice> --> <!-- AOP 事务处理 结束 --> <!-- 用注解的方式处理事务 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!--mybatis自动扫描加载Sql映射文件/接口 : MapperScannerConfigurer sqlSessionFactorybasePackage:指定sql映射文件/接口所在的包(自动扫描) --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="cn.dao,cn.service"></property> <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean> </beans> 在设置数据库解密时要加上生成的公钥以进行解密
01-11
3655

“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交