自动化立体仓库 - WMS系统
ZY
1 天以前 a04129405c79496236fff3b1fd8de5b70c5b3fda
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
44
45
46
47
48
49
package com.zy.common.config.ds;
 
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
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 javax.sql.DataSource;
 
import static com.sun.xml.internal.ws.spi.db.BindingContextFactory.LOGGER;
 
@Configuration
public class DataSourceConfig {
 
    @Value("${other.datasource.jdbc-url}")
    private String url;
    @Value("${other.datasource.username}")
    private String username;
    @Value("${other.datasource.password}")
    private String password;
    @Value("${other.datasource.driver-class-name}")
    private String driverClassName;
 
    // 主数据源
    @Bean(name = "dataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }
 
    // 次数据源
    @Bean(name = "slaveDataSource")
    public DataSource secondaryDataSource() {
        System.out.println(driverClassName);
        return DataSourceBuilder.create()
                .driverClassName(driverClassName)
                .url(url)
                .username(username)
                .password(password)
                .build();
 
    }
 
}