Я настраиваю свой источник данных в моем проекте, который был развернут на PCF, и есть проблема с производительностью sqlserver, поэтому я хочу добавить свойство: sendStringParametersAsUnicode = false , чтобы исправить эту проблему, просто в качестве локальной настройки jdbcUrl: url: jdbc:sqlserver://localhost:1433;databaseName=localdatasource;sendStringParametersAsUnicode=false
,
Но я пробовал оба приведенных ниже кода, кажется, что connectionConfig не работает.
Code1 ссылка Руководство по коннекторам Spring Cloud Spring
@Configuration
@Profile({"dev", "sit", "uat", "prod"})
@Slf4j
public class CloudConfig extends AbstractCloudConfig {
@Value("${datasourceinfo.min-idle}")
private int dataSourceMinPoolSize = 20;
@Value("${datasourceinfo.max-active}")
private int dataSourceMaxPoolSize = 100;
@Value("${datasourceinfo.max-wait}")
private int dataSourceMaxWaitTime = -1;
@Value("${datasourceinfo.azureDatabase}")
private String azureDatabase;
@Bean
@Primary
public DataSource dataSource() {
PooledServiceConnectorConfig.PoolConfig poolConfig = new PooledServiceConnectorConfig.PoolConfig(dataSourceMinPoolSize, dataSourceMaxPoolSize, dataSourceMaxWaitTime);
DataSourceConfig.ConnectionConfig connConfig = new DataSourceConfig.ConnectionConfig("sendStringParametersAsUnicode=false");
DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, connConfig);
log.info("======================init dataSource connProperties {}",dbConfig);
return connectionFactory().dataSource(azureDatabase, dbConfig);
}
}
Code2 : следуйте советам здесь: Проблема с коннекторами Spring Cloud
@Primary
public DataSource dataSource() {
PooledServiceConnectorConfig.PoolConfig poolConfig = new PooledServiceConnectorConfig.PoolConfig(dataSourceMinPoolSize, dataSourceMaxPoolSize, dataSourceMaxWaitTime);
Map<String, Object> connProperties = new HashMap<>();
connProperties.put("connectionProperties","sendStringParametersAsUnicode=false");
DataSourceConfig dbConfig = new DataSourceConfig(poolConfig,null,null,connProperties);
log.info("======================init dataSource connProperties {}",dbConfig);
return connectionFactory().dataSource(azureDatabase, dbConfig);
}
Журналы, как показано ниже:
2020-05-26T20:13:48.724+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.724+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] HikariPool-1 - configuration:
2020-05-26T20:13:48.727+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.727+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] connectionTestQuery............."SELECT 1"
2020-05-26T20:13:48.727+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.727+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] connectionTimeout...............30000
2020-05-26T20:13:48.728+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.728+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] driverClassName................."com.microsoft.sqlserver.jdbc.SQLServerDriver"
2020-05-26T20:13:48.729+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.729+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] jdbc4ConnectionTest.............false
2020-05-26T20:13:48.729+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.729+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] jdbcUrl.........................**jdbc:sqlserver://myIp:1433;database=devDb;user=u4a1780c36;password=<masked>;Encrypt=true;TrustServerCertificate=false;HostNameInCertificate=*.database.windows.net;loginTimeout=30;**
2020-05-26T20:13:48.729+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.729+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] leakDetectionThreshold..........0
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.729+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] maxLifetime.....................1800000
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.730+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] maximumPoolSize.................100
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.730+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] metricRegistry..................none
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.730+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] metricsTrackerFactory...........com.zaxxer.hikari.metrics.micrometer.MicrometerMetricsTrackerFactory@75add13c
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.730+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] minimumIdle.....................20
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.730+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] password........................<masked>
2020-05-26T20:13:48.730+08:00 [APP/PROC/WEB/0] [OUT] DEBUG . [26-05-2020 20:13:48.730+0800] [main] [springAppName_IS_UNDEFINED,,,] [c.z.h.HikariConfig] poolName........................"HikariPool-1"
Из журналов я обнаружил, что PoolConfig [minimumIdle = 20, maximumPoolSize = 100] был обновлен, но ConnectionConfig был проигнорирован, и я не знаю, что произошло или что-то не так с моим кодом. Спасибо.