【发布时间】:2016-08-30 14:41:59
【问题描述】:
我正在使用带有池化数据源的 Spring Boot
datasource:
type: org.apache.tomcat.jdbc.pool.DataSource
driverClassName: com.mysql.jdbc.Driver
url: ...
username: ...
password: ...
tomcat:
max-active: 50
max-idle: 50
testOnBorrow: true
validationQuery: select 1;
validationInterval: 30000
这个配置是正确的,因为日志文件包含 10x 以下行:
16:27:52.191 [] [ restartedMain] DEBUG g.apache.tomcat.jdbc.pool.PooledConnection - Instantiating driver using class: com.mysql.jdbc.Driver [url=...]
之后,我开始使用该应用程序并发出一些数据库请求。 DAO 实现使用 JPAContext 和 EntityManager,由 Spring 自动装配并完美地从数据库返回预期结果。
@Autowired
private JpaContext jpaContext;
@Autowired
private EntityManager em;
EntityManager em = jpaContext.getEntityManagerByManagedType(DownloadHistoryItemCustomEntity.class);
Query q = em.createNativeQuery(query, DownloadHistoryItemCustomEntity.class);
但是,Spring Boot 指标并未显示该单个数据源的任何使用情况
http://localhost:8080/metrics
"datasource.primary.active": 0,
"datasource.primary.usage": 0.0
为什么没有值 > 0 ?
我希望值大于零!
“主要”不是正确的数据源吗?
多米尼克
【问题讨论】:
标签: spring-boot metrics tomcat-jdbc