DataSourceConfig.java
1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.bsth;
import org.springframework.beans.factory.annotation.Qualifier;
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.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
/**
* @author Hill
*/
@Configuration
public class DataSourceConfig {
@Bean(name = "controlDataSource")
@Qualifier("controlDataSource")
@ConfigurationProperties(prefix = "spring.datasource.control")
public DataSource controlDataSource(){
return DataSourceBuilder.create().build();
}
@Bean(name = "msDataSource")
@Qualifier("msDataSource")
@Primary
@ConfigurationProperties(prefix = "spring.datasource.ms")
public DataSource msDataSource(){
return DataSourceBuilder.create().build();
}
@Bean(name = "controlJdbcTemplate")
public JdbcTemplate controlJdbcTemplate(@Qualifier("controlDataSource")DataSource dataSource){
return new JdbcTemplate(dataSource);
}
@Bean(name = "msJdbcTemplate")
public JdbcTemplate msJdbcTemplate(@Qualifier("msDataSource")DataSource dataSource){
return new JdbcTemplate(dataSource);
}
}