1、继承多数据库

Former-commit-id: 8a0b347c120ab04c46207489dd6fbea675703c74
master
wangbing 5 years ago
parent 298c13d927
commit 137275a8cd

@ -1,4 +1,4 @@
package com.example.config; package ${basePackage}.config;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionFactoryBean;
@ -15,7 +15,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource; import javax.sql.DataSource;
@Configuration @Configuration
@MapperScan(basePackages = {"com.example.*.mainMpr"}, sqlSessionFactoryRef = "mainSqlSessionFactory") @MapperScan(basePackages = {"${basePackage}.*.mainMpr"}, sqlSessionFactoryRef = "mainSqlSessionFactory")
public class MapperMainConfig { public class MapperMainConfig {
@Bean(name = "mainDataSource") @Bean(name = "mainDataSource")
@Primary @Primary
@ -35,7 +35,7 @@ public class MapperMainConfig {
public SqlSessionFactory basicSqlSessionFactory(@Qualifier("mainDataSource") DataSource basicDataSource) throws Exception { public SqlSessionFactory basicSqlSessionFactory(@Qualifier("mainDataSource") DataSource basicDataSource) throws Exception {
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(basicDataSource); factoryBean.setDataSource(basicDataSource);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/example/**/mainMpr/*.xml")); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:**/mainMpr/*.xml"));
return factoryBean.getObject(); return factoryBean.getObject();
} }
} }

@ -1,4 +1,4 @@
package com.example.config; package ${basePackage}.config;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionFactoryBean;
@ -14,7 +14,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource; import javax.sql.DataSource;
@Configuration @Configuration
@MapperScan(basePackages = {"com.example.*.twoMpr"}, sqlSessionFactoryRef = "twoSqlSessionFactory") @MapperScan(basePackages = {"${basePackage}.*.twoMpr"}, sqlSessionFactoryRef = "twoSqlSessionFactory")
public class MapperTwoConfig { public class MapperTwoConfig {
@Bean(name = "TwoDataSource") @Bean(name = "TwoDataSource")
@ConfigurationProperties(prefix = "spring.datasource.two") @ConfigurationProperties(prefix = "spring.datasource.two")
@ -31,7 +31,7 @@ public class MapperTwoConfig {
public SqlSessionFactory basicSqlSessionFactory(@Qualifier("twoDataSource") DataSource basicDataSource) throws Exception { public SqlSessionFactory basicSqlSessionFactory(@Qualifier("twoDataSource") DataSource basicDataSource) throws Exception {
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(basicDataSource); factoryBean.setDataSource(basicDataSource);
factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/example/**/twoMpr/*.xml")); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:**/twoMpr/*.xml"));
return factoryBean.getObject(); return factoryBean.getObject();
} }
} }

@ -186,7 +186,7 @@
<resource> <resource>
<directory>src/main/java</directory> <directory>src/main/java</directory>
<includes> <includes>
<include>**/mpr/*.xml</include> <include>**/*Mapper.xml</include>
</includes> </includes>
</resource> </resource>
<!-- 包含lib中所有jar包 --> <!-- 包含lib中所有jar包 -->

Loading…
Cancel
Save

Powered by TurnKey Linux.