好吧,我已经将
jdbcTemplate
融入到了某堂课中:
@Service
public MyService {
@Autowired
private JdbcTemplate jdbcTemplate;
}
但是如何从中获取连接池实现呢?我看到
getDataSource()
方法,但是 DataSource
没有关于连接池的内容:(
例如,如果您的依赖项管理器中有此依赖项
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
DataSource
接口的实现将是HikariDataSource
,这是Spring将用于构造JdbcTemplate
的实例。
现在,当您在代码中调用
jdbcTemplate.getDataSource().getConnection()
时 HikariDataSource
从池中获取连接。