springboot2 默认数据库连接池HikariCP

1.Springboot2默认数据库连接池选择了HikariCP为何选择HikariCP

    理由一、代码量

    理由二、口碑

    理由三、速度

    理由四、稳定性

    理由五、可靠性

2.druid对数据源进行了监控,但是我们知道sharding-jdbc, mycat等都可以监控。

3.我们这里给出一个例子看看怎么使用以及速度如何

4.环境:jdk8,springboot 2.0.2release.

@RestController
@Slf4j
public class UserController {
	
	@Autowired
	private UserService UserService;
	
	@RequestMapping("/user/{id}")
	public User getById(@PathVariable Long id) {
		log.info("id={}",id);
		return UserService.getById(id);
	}
}
logging.level.root=info
logging.level.com.security=info
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.pool-name=DatebookHikariCP

mybatis.type-aliases-package=com.security.model
mybatis.mapper-locations=classpath:/mybatis/*

		org.springframework.boot
		spring-boot-starter-parent
		2.0.2.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter
		
		
			org.springframework.boot
			spring-boot-starter-web
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
			mysql
			mysql-connector-java
		
		
			org.mybatis.spring.boot
			mybatis-spring-boot-starter
			1.3.1
		
		
			org.projectlombok
			lombok
			
	

运行结果:

 Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
springboot2 默认数据库连接池HikariCP_第1张图片



你可能感兴趣的:(java)