Commit 6e73a34f by 张祺

去除第二数据源,修改mapper配置

parent 22e16976
......@@ -32,7 +32,10 @@
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<groupId>org.springframework.boot</groupId>t
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
......
package com.keymobile.indicators.conf;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@Configuration
@MapperScan(basePackages = "com.keymobile.indicators.model.mapper", sqlSessionTemplateRef = "secondSqlSessionTemplate")
public class SecondDatasourceConf {
@Primary //指定主库
@Bean
@ConfigurationProperties(prefix = "spring.datasource.second")
public DataSource secondDatasource() {
return DataSourceBuilder.create().build();
}
@Bean
public SqlSessionFactory secondSqlSessionFactory() throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(secondDatasource());
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapping/*Mapper.xml"));
return sqlSessionFactoryBean.getObject();
}
@Bean
public DataSourceTransactionManager secondTxMananger() {
return new DataSourceTransactionManager(secondDatasource());
}
@Bean
public SqlSessionTemplate secondSqlSessionTemplate() throws Exception {
return new SqlSessionTemplate(secondSqlSessionFactory());
}
}
......@@ -2,11 +2,12 @@ package com.keymobile.indicators.model.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import com.keymobile.indicators.model.entity.T1;
@Repository
@Mapper
public interface T1Mapper {
List<T1> selAll();
}
......@@ -17,11 +17,6 @@ spring:
password: test
hikari:
maximum-pool-size: 3
second:
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://139.198.127.54:9306/dev0?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
username: test
password: test
servlet:
multipart:
max-file-size: 20Mb
......@@ -54,4 +49,5 @@ security:
authPwd: pwd
mybatis:
mapper-locations: classpath:/mybatis/mapping/*.xml
type-aliases-package: com.keymobile.indicators.model.entity
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment