Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HIKARIP与jooq的连接太多_Java_Mysql_Spring_Jooq_Hikaricp - Fatal编程技术网

Java HIKARIP与jooq的连接太多

Java HIKARIP与jooq的连接太多,java,mysql,spring,jooq,hikaricp,Java,Mysql,Spring,Jooq,Hikaricp,在springrestfulapi中使用jooq和HikariCP数据源(Autowired)时,我遇到了一个问题,jooq不知何故没有释放数据源 一些代码: @Autowired private DataSource dataSource; //Further down DSLContext create = DSL.using(dataSource, SQLDialect.MYSQL); 使用此存储库/呼叫两三次后,我打开的连接太多 My dispatcher-servlet.xml:

在springrestfulapi中使用jooq和HikariCP数据源(Autowired)时,我遇到了一个问题,jooq不知何故没有释放数据源

一些代码:

@Autowired
private DataSource dataSource;
//Further down 
DSLContext create = DSL.using(dataSource, SQLDialect.MYSQL);
使用此存储库/呼叫两三次后,我打开的连接太多

My dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd">

    <context:component-scan base-package="com.rh" />

     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="20971520"/> <!-- 20 MB -->
    </bean>

    <context:property-placeholder location="classpath:database/database.properties"/>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
        <property name="poolName" value="springHikariCP" />
        <property name="connectionTestQuery" value="SELECT 1" />
        <property name="dataSourceClassName" value="${jdbc.driver}" />
        <property name="maximumPoolSize" value="20" />
        <property name="idleTimeout" value="20" />

        <property name="dataSourceProperties">
            <props>
                <prop key="url">${jdbc.url}</prop>
                <prop key="user">${jdbc.username}</prop>
                <prop key="password">${jdbc.password}</prop>
                <prop key="prepStmtCacheSize">50</prop>
                <prop key="prepStmtCacheSqlLimit">50</prop>
                <prop key="cachePrepStmts">true</prop>
                <prop key="useServerPrepStmts">true</prop>                
            </props>
        </property>
    </bean>

    <!-- HikariCP configuration -->
    <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
        <constructor-arg ref="hikariConfig" />
    </bean> 

    <bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
        <!--<beans:constructor-arg value="256" />-->
        <!--<beans:property name="iterations" value="1000" />-->
    </bean>  

    <!--Different providers-->
    <bean id="cloudinaryProvider" class="com.rh.bean.CloudinaryProvider"></bean>
    <bean id="s3Provider" class="com.rh.bean.S3Provider"></bean>    

    <bean id="objectMapper" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean" autowire="no">
        <property name="propertyNamingStrategy" value="CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES" />
    </bean>
    <mvc:annotation-driven>
        <mvc:path-matching suffix-pattern="false" trailing-slash="false" />
        <mvc:argument-resolvers>
            <bean class="com.rh.util.CurrentUserHandlerMethodArgumentResolver"/>         
        </mvc:argument-resolvers>        
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="objectMapper">
                    <ref bean="objectMapper" />
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven> 

    <security:global-method-security pre-post-annotations="enabled" secured-annotations="enabled"></security:global-method-security> 
</beans>

${jdbc.url}
${jdbc.username}
${jdbc.password}
50
50
真的
真的

好,我修复了问题:

    @Autowired
private DataSource dataSource;
//Further down 
Connection con=dataSource.getConnection();
DSLContext create = DSL.using(con, SQLDialect.MYSQL);
//Execute code here
con.close();

因此,我没有直接使用数据源,而是使用了一个连接并发布了它。

很久以前,jOOQ中存在与连接管理相关的bug。您使用的jOOQ版本是什么?谢谢您的帮助;)版本3.7.3好的,很有趣。您可以记录与数据源的交互吗?也就是说,谁正在从中获取连接,谁正在再次关闭连接?你能展示一些更多的JooQAPI用法来帮助重现这一点吗,或者你的项目已经非常大了吗?不,我会这么做。明天将发布更多代码!非常感谢:)我实际上认为这是因为自动连线——但通常情况下,jooq应该只发布数据源。是的,jooq在内部使用
DataSourceConnectionProvider
(在版本2.x中有bug,因此我的最初评论)。
ConnectionProvider
应负责在查询后关闭所有连接。。。从高层次来看,您的jOOQ用法似乎是正确的。