达梦数据库配置-主备

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

yml 配置

spring:  
  datasource:
    driver-class-name: dm.jdbc.driver.DmDriver
    url: 'jdbc:dm://dwc/prod?dwc=xx.xx.xx.xx:1112,xx.xx.xx.xx:1113&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)&LOGIN_MODE=1'
    jdbc-url: 'jdbc:dm://dwc/prod?dwc=xx.xx.xx.xx:1112,xx.xx.xx.xx:1113&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)&LOGIN_MODE=1'
    username: prod
    password: xxxx

配置:properties

spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
spring.datasource.url=jdbc:dm://dwc/prod?dwc=(xx.x.x.x:5236)&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)&LOGIN_MODE=1
#spring.datasource.url=jdbc:dm://x.x.x.x:5236/prod?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)
spring.datasource.username=prod
spring.datasource.password=er1:
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
spring.datasource.url=jdbc:dm://dwc/zdpro?dwc=(172.100.101.80:5236,172.100.101.81:5236)&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)&LOGIN_MODE=1
#spring.datasource.url=jdbc:dm://172.100.100.80:5236/zdpro?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)
spring.datasource.username=zdpro
spring.datasource.password=er1:C/

cas的jpa配置

cas.serviceRegistry.jpa.user=zdpro
cas.serviceRegistry.jpa.password=er1:C
cas.serviceRegistry.jpa.driverClass=dm.jdbc.driver.DmDriver
cas.serviceRegistry.jpa.url=jdbc:dm://dwc/pro?dwc=(172.100.100.80:5236)&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&TIME_ZONE=(+480)&LOGIN_MODE=1
#cas.serviceRegistry.jpa.url=jdbc:dm://172.100.100.80:5236/pro?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8
cas.serviceRegistry.jpa.dialect=org.hibernate.dialect.DmDialect

集成Hikari

@Bean
	public DataSource dataSource() {
		val bean = new HikariDataSource();
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.driver-class-name"))) {
			bean.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
		}
		bean.setJdbcUrl(env.getProperty("spring.datasource.url"));
		bean.setUsername(env.getProperty("spring.datasource.username"));
		bean.setPassword(env.getProperty("spring.datasource.password"));
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.minimum-idle"))) {
			bean.setMinimumIdle(Integer.parseInt(env.getProperty("spring.datasource.hikari.minimum-idle")));
		} else {
			bean.setMinimumIdle(6);
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.maximum-pool-size"))) {
			bean.setMaximumPoolSize(Integer.parseInt(env.getProperty("spring.datasource.hikari.maximum-pool-size")));
		} else {
			bean.setMaximumPoolSize(18);
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.auto-commit"))) {
			bean.setAutoCommit(Boolean.parseBoolean(env.getProperty("spring.datasource.hikari.auto-commit")));
		} else {
			bean.setAutoCommit(true);
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.idle-timeout"))) {
			bean.setIdleTimeout(Integer.parseInt(env.getProperty("spring.datasource.hikari.idle-timeout")));
		} else {
			bean.setIdleTimeout(30000);
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.pool-name"))) {
			bean.setPoolName(env.getProperty("spring.datasource.hikari.pool-name"));
		} else {
			bean.setPoolName("DatebookHikariCP");
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.max-lifetime"))) {
			bean.setMaxLifetime(Integer.parseInt(env.getProperty("spring.datasource.hikari.max-lifetime")));
		} else {
			bean.setMaxLifetime(1800000);
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.connection-timeout"))) {
			bean.setConnectionTimeout(Integer.parseInt(env.getProperty("spring.datasource.hikari.connection-timeout")));
		} else {
			bean.setConnectionTimeout(30000);
		}
		if (StringUtils.isNotBlank(env.getProperty("spring.datasource.hikari.leakDetectionThreshold"))) {
			bean.setLeakDetectionThreshold(
					Integer.parseInt(env.getProperty("spring.datasource.hikari.leakDetectionThreshold")));
		} else {
			bean.setLeakDetectionThreshold(60000);
		}
		return bean;
	}
posted @ 2024-01-30 20:57  倔强的老铁  阅读(40)  评论(0编辑  收藏  举报