springとmybatisは配置ファイルを統合します。
最近はプロジェクトの要求でスプリング+mybatisアーキテクチャを統合してプロジェクトを開発しています。
基本アーキテクチャ:spring+springmvc+mybatis
分布式フレーム:dubbo+zookeeper
データベース:mysql
データベース接続池:ドルイド
1データベース接続設定情報jdbc.properties
以上は小编でご绍介したspringとmybatisの统合配置ファイルです。皆さんに助けてほしいです。もし何かご质问があれば、メッセージをください。小编はすぐに返事します。ここでも私たちのサイトを応援してくれてありがとうございます。
基本アーキテクチャ:spring+springmvc+mybatis
分布式フレーム:dubbo+zookeeper
データベース:mysql
データベース接続池:ドルイド
1データベース接続設定情報jdbc.properties
#mysql version database druid
# setting
validationQuery=SELECT 1
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ivan?useUnicode=true&characterEncoding=utf-8&useSSL=true
jdbc.username=root
jdbc.password=root
2 springプロファイルspring-register.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- -->
<!-- <context:property-placeholder location="classpath:config/jdbc.properties"/>-->
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/zookeeper.properties</value>
<value>classpath:config/jdbc.properties</value>
<value>classpath:config/log4j.properties</value>
</list>
</property>
</bean>
<bean id="userService" class="com.ivan.dubbo.service.impl.UserServiceImpl"/>
<!-- , -->
<dubbo:application name="ivan-dubbo-server"></dubbo:application>
<!-- zookeeper -->
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />
<!-- -->
<!-- <dubbo:registry protocol="zookeeper" address="zookeeper://127.0.0.1:4170?backup=127.0.0.1:4180,127.0.0.1:4190" />-->
<!-- <dubbo:registry protocol="zookeeper" address="127.0.0.1:4170,127.0.0.1:4180,127.0.0.1:4190"/>-->
<!-- <dubbo:registry id="ivan-dubbo-server1" protocol="zookeeper" address="127.0.0.1:4170" />
<dubbo:registry id="ivan-dubbo-server2" protocol="zookeeper" address="127.0.0.1:4180" />
<dubbo:registry id="ivan-dubbo-server3" protocol="zookeeper" address="127.0.0.1:4190" />
-->
<!--- dubbo 20880 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!--
: , , pacakge ApplicationContext 。
: package Service, 。
-->
<dubbo:annotation package="com"/>
<dubbo:service interface="com.ivan.service.provider.UserService" ref="userService" timeout="1200000"></dubbo:service>
</beans>
3 spring-mybatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
<!-- -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- -->
<property name="initialSize" value="5"/>
<property name="maxActive" value="20"/>
<!-- -->
<property name="minIdle" value="0"/>
<!-- -->
<property name="maxWait" value="60000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxPoolPreparedStatementPerConnectionSize" value="33"/>
<!-- sql-->
<property name="validationQuery" value="${validationQuery}"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="testWhileIdle" value="true"/>
<!-- , , -->
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<!-- , -->
<property name="minEvictableIdleTimeMillis" value="25200000"/>
<!-- removeAbandoned -->
<property name="removeAbandoned" value="true"/>
<!-- 1800 , 30 -->
<property name="removeAbandonedTimeout" value="1800"/>
<!-- abanded -->
<property name="logAbandoned" value="true"/>
<!-- -->
<property name="filters" value="mergeStat"/>
</bean>
<!--MyBatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:com/ivan/**/mapping/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ivan.dubbo.service.dao.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- -->
<!-- <tx:annotation-driven transaction-manager="transactionManager"/>-->
<!-- -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--
<span style="font-family:FangSong_GB2312;"> </span>Spring aop
<span style="font-family:FangSong_GB2312;"> , </span>
-->
<!-- <aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.ivan..service.impl.*Impl.*(..))" />
<aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionPointcut"/>
</aop:config> -->
</beans>
締め括りをつける以上は小编でご绍介したspringとmybatisの统合配置ファイルです。皆さんに助けてほしいです。もし何かご质问があれば、メッセージをください。小编はすぐに返事します。ここでも私たちのサイトを応援してくれてありがとうございます。