Commit 917f2b6c by 胡涛

注释数据源

parent bf1ed5e1
...@@ -61,6 +61,12 @@ ...@@ -61,6 +61,12 @@
<artifactId>cloud-wechat-api</artifactId> <artifactId>cloud-wechat-api</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.yizhi.course.application.config; //package com.yizhi.course.application.config;
//
import com.zaxxer.hikari.HikariConfig; //import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; //import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
//
import javax.sql.DataSource; //import javax.sql.DataSource;
//
/** ///**
* HikariCP连接池配置 // * HikariCP连接池配置
*/ // */
@Configuration //@Configuration
public class DataSourceConfig { //public class DataSourceConfig {
//
@Value("${spring.datasource.url}") // @Value("${spring.datasource.url}")
private String dataSourceUrl; // private String dataSourceUrl;
//
@Value("${spring.datasource.username}") // @Value("${spring.datasource.username}")
private String user; // private String user;
//
@Value("${spring.datasource.password}") // @Value("${spring.datasource.password}")
private String password; // private String password;
//
@Bean // @Bean
public DataSource dataSource() { // public DataSource dataSource() {
HikariConfig config = new HikariConfig(); // HikariConfig config = new HikariConfig();
/** 数据源 */ // /** 数据源 */
config.setJdbcUrl(dataSourceUrl); // config.setJdbcUrl(dataSourceUrl);
/** 用户名 */ // /** 用户名 */
config.setUsername(user); // config.setUsername(user);
/** 密码 */ // /** 密码 */
config.setPassword(password); // config.setPassword(password);
/** 是否自定义配置,为true时下面两个参数才生效 */ // /** 是否自定义配置,为true时下面两个参数才生效 */
config.addDataSourceProperty("cachePrepStmts", "true"); // config.addDataSourceProperty("cachePrepStmts", "true");
/** 连接池大小默认25,官方推荐250-500 */ // /** 连接池大小默认25,官方推荐250-500 */
config.addDataSourceProperty("prepStmtCacheSize", "250"); // config.addDataSourceProperty("prepStmtCacheSize", "250");
/** 单条语句最大长度默认256,官方推荐2048 */ // /** 单条语句最大长度默认256,官方推荐2048 */
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); // config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
/** 新版本MySQL支持服务器端准备,开启能够得到显著性能提升 */ // /** 新版本MySQL支持服务器端准备,开启能够得到显著性能提升 */
config.addDataSourceProperty("useServerPrepStmts", "true"); // config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("useLocalSessionState", "true"); // config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("useLocalTransactionState", "true"); // config.addDataSourceProperty("useLocalTransactionState", "true");
config.addDataSourceProperty("rewriteBatchedStatements", "true"); // config.addDataSourceProperty("rewriteBatchedStatements", "true");
config.addDataSourceProperty("cacheResultSetMetadata", "true"); // config.addDataSourceProperty("cacheResultSetMetadata", "true");
config.addDataSourceProperty("cacheServerConfiguration", "true"); // config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true"); // config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("maintainTimeStats", "false"); // config.addDataSourceProperty("maintainTimeStats", "false");
//
HikariDataSource ds = new HikariDataSource(config); // HikariDataSource ds = new HikariDataSource(config);
return ds; // return ds;
} // }
//
} //}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment