| | |
| | | package com.vincent.rsf.server.common.config; |
| | | |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | |
| | | import javax.sql.DataSource; |
| | | |
| | | /** |
| | | * cus_item_sync_view 专用副库连接;未配置 cus-item-sync.datasource.url 时不创建 Bean,查询回退主库 Mapper |
| | | * 鼎捷 专用副库连接 |
| | | */ |
| | | @Configuration |
| | | @ConditionalOnProperty(prefix = "cus-item-sync.datasource", name = "url") |
| | | @EnableConfigurationProperties(CusItemSyncDataSourceProperties.class) |
| | | @ConditionalOnProperty(prefix = "spring.datasource.dj-cloud-wms", name = "url") |
| | | public class CusItemSyncDataSourceConfig { |
| | | |
| | | @Bean(name = "cusItemSyncDataSource") |
| | | public DataSource cusItemSyncDataSource(CusItemSyncDataSourceProperties p) { |
| | | DruidDataSource ds = new DruidDataSource(); |
| | | ds.setUrl(p.getUrl()); |
| | | ds.setUsername(p.getUsername()); |
| | | ds.setPassword(p.getPassword()); |
| | | ds.setDriverClassName(p.getDriverClassName()); |
| | | ds.setInitialSize(2); |
| | | ds.setMinIdle(2); |
| | | ds.setMaxActive(10); |
| | | ds.setMaxWait(30000); |
| | | ds.setTestWhileIdle(true); |
| | | ds.setValidationQuery("SELECT 'x'"); |
| | | return ds; |
| | | } |
| | | |
| | | @Bean(name = "cusItemSyncJdbcTemplate") |
| | | public JdbcTemplate cusItemSyncJdbcTemplate(@Qualifier("cusItemSyncDataSource") DataSource dataSource) { |
| | | return new JdbcTemplate(dataSource); |
| | | @ConfigurationProperties(prefix = "spring.datasource.dj-cloud-wms") |
| | | public DataSource cusItemSyncDataSource() { |
| | | return new DruidDataSource(); |
| | | } |
| | | } |