我有一个spring应用程序,其主页触发多个ajax调用,然后从DB获取数据并返回.数据库已配置连接池,minPoolSize为50,maxPoolSize为100.
现在,当我打开主页时,与DB建立了大约7个连接,预计大约有7个ajax调用,我假设它们都创建了自己的连接.现在,当我刷新页面时,我看到另外7个新连接建立(我看到来自db2监控的总共14个物理连接),这似乎是意外的,因为我假设jdbcTemplate在第一次访问和刷新查询后关闭连接在这种情况下应该重用连接?
现在的问题是,结果集是否也被jdbcTemplate关闭以及连接关闭?或者我是否需要显式关闭resultSet以便可以自动关闭连接.打开的resultSet可能是连接没有关闭的原因?附加连接池配置的代码
<dataSource jdbcDriverRef="db2-driver" jndiName="jdbc/dashDB-Development" transactional="true" type="javax.sql.DataSource">
<properties.db2.jcc databaseName="BLUDB" id="db2-dashDB-Development-props" password="********" portNumber="*****" serverName="*********" sslConnection="false" user="*****"/>
<connectionManager id="db2-DashDB-Development-conMgr" maxPoolSize="100" minPoolSize="50" numConnectionsPerThreadLocal="2"/>
Run Code Online (Sandbox Code Playgroud)
我的初步理论是,只有达到minPoolSize才会重复使用连接,直到那时它总会创建新的物理连接.我甚至在达到这个限制后也看到了这种行为.我刷新了我的页面10次,我看到70个物理连接.现在我唯一的疑问是,连接在某种程度上没有接近,春天看到这些连接忙吗?这可能是因为结果集未关闭或其他原因?这是一种说jdbctemplate不等待结束时间超过时间限制的方法吗?
谢谢Manoj
我试图使用本地云弹簧连接器在本地环境中测试我的应用程序,然后才能将其部署到基于CF的云环境中。从春季链接
我按照此过程进行操作,并在项目资源目录中创建了名称为spring-cloud-bootstrap.properties的属性文件。它具有以下内容
spring.cloud.properties文件:C:\ Users \ IBM_ADMIN \ git \ ServiceXchange5 \ ServiceXchange \ spring-cloud.properties
我在上面给出的路径中确实有文件spring-cloud.properties。
从spring configuaration bean中,我有以下内容
@EnableWebMvc
@Configuration
@EnableAspectJAutoProxy
public class CloudServiceConfig extends AbstractCloudConfig {
@Bean
public DataSource getDataSource() throws AppException {
org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig poolConfig = new PoolConfig(50, 100, 3000);
org.springframework.cloud.service.relational.DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, null);
return connectionFactory().dataSource(SX_DB_USED, dbConfig);
}
Run Code Online (Sandbox Code Playgroud)
现在,此DataSource bean被注入了其他地方。将属性文件放置在适当的位置,我希望将创建用于本地配置的云连接器bean,并且我应该能够使用该连接器为DataSource添加更多配置以用于连接池。
但是,当我访问该应用程序时,它似乎未激活本地配置连接器。
Initialization of bean failed; nested exception is org.springframework.cloud.CloudException: No suitable cloud connector found
[ERROR ] SRVE0271E: Uncaught init() exception created by servlet [appServlet] in application …Run Code Online (Sandbox Code Playgroud) spring spring-boot spring-cloud spring-cloud-connectors spring-cloud-config