我将Hikari与SQL Server 2016和tomcat lib文件夹中的sqljdbc4-2.0.jar一起使用。
我对数据库资源的配置如下:
<Resource name="jdbc/SQLServerDS" auth="Container" type="javax.sql.DataSource"
username="uname"
password="pwd"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://server:port;DatabaseName=dbName"
maxActive="20"
maxIdle="10"
validationQuery="select 1" />
Run Code Online (Sandbox Code Playgroud)
我的数据源配置如下:
@Bean(name = "dataSource")
public DataSource getDataSource() throws NamingException {
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(20);
config.setDataSourceJNDI("java:comp/env/jdbc/SQLServerDS");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("cacheResultSetMetadata", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("maintainTimeStats", "false");
return new TransactionAwareDataSourceProxy(
new LazyConnectionDataSourceProxy(new HikariDataSource(config)));
}
Run Code Online (Sandbox Code Playgroud)
我如何知道preparestatement缓存是否适用于不同的连接?
我正在将Spring容器管理的事务与hibernate v4.3.10.Final一起使用。
另外,为了使缓存起作用,是否需要启用二级缓存?