配置文件
logging:
config: classpath:log4j2.xml
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://XXX.XXXX.XXX.XXXX:XXXX/eureka/
healthcheck:
enabled: false
server:
port: 9527
management:
security:
enabled: false
endpoints:
health:
sensitive: false
spring:
application:
name: telecom-cloud-collection
mybatis:
mapper-locations: classpath*:mapper/**/*.xml
type-aliases-package: com.chinamobile.cmss.telecom.cloud
type-handlers-package: com.eyougo.mybatis.postgis.type
config-location: classpath:/mybatis-config.xml
configuration:
log-impl: org.apache.ibatis.logging.log4j2.Log4j2Impl
datasource:
names: resources,dataCenter
resources:
write:
url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
read:
names: read01,read02,read03
readSize: 3 #读库个数
weights: 3,3,4 #读库权重
class: com.chinamobile.cmss.gvrms.datasource.read.WeightsReadStrategy
read01:
url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
read02:
url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
read03:
url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/rms_province
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
dataCenter:
write:
url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/nanjingfgm?currentSchema=cmss&useUnicode=true&characterEncoding=UTF-8&allowMultiQuer
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
read:
names: o4Center
o4Center:
url: jdbc:postgresql://XXX.XXXX.XXX.XXXX:XXXX/nanjingfgm?currentSchema=cmss&useUnicode=true&characterEncoding=UTF-8&allowMultiQuer
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
minIdle: 5
maxActive: 10
initialSize: 2
maxWait: 60000
timeBetweenEvictionRunsMillis: -1
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 50
removeAbandoned: false
filters: stat
feign:
hystrix:
enabled: true
hystrix:
threadpool:
default:
coreSize: 200
maxQueueSize: 200
queueSizeRejectionThreshold: 50
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 300000
circuitBreaker:
sleepWindowInMilliseconds: 300000
forceClosed: true
ribbon:
ReadTimeout: 300000
SocketTimeout: 300000
ConnectTimeout: 300000
OkToRetryOnAllOperations: true
MaxAutoRetries: 1
MaxAutoRetriesNextServer: 2
注解
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface WriteDataSource {
/**
* 默认使用resources集群库
* @return
*/
String name() default "resources";
/**
* 具体数据库
* @return
*/
String database() default "";
}
java文件
/**
* Created by 18317 on 2019/11/24.
*/
@Service
@Slf4j
@WriteDataSource(name = "dataCenter", database = "o4Center")
public class ONfvoCmVnfDService {
@Autowired
private ONfvoCmVnfDMapper oNfvoCmVnfDMapper;
public List<ONfvoCmVnfD> selectByNowDate () {
return oNfvoCmVnfDMapper.selectByNowDate();
}
}