首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HikariCP与jooq的连接太多了

HikariCP与jooq的连接太多了
EN

Stack Overflow用户
提问于 2016-04-20 13:48:53
回答 1查看 1.7K关注 0票数 2

当我在中使用jooq和HikariCP DataSource (自动头发)时,我发现问题是,jooq不知怎么没有发布DataSource。

一些法典:

代码语言:javascript
复制
@Autowired
private DataSource dataSource;
//Further down 
DSLContext create = DSL.using(dataSource, SQLDialect.MYSQL);

在使用这个存储库/调用两三次之后,我打开了太多的连接。

我的dispatcher-servlet.xml:

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-27 08:38:14

好的,我解决了这个问题:

代码语言:javascript
复制
    @Autowired
private DataSource dataSource;
//Further down 
Connection con=dataSource.getConnection();
DSLContext create = DSL.using(con, SQLDialect.MYSQL);
//Execute code here
con.close();

因此,我没有直接使用DataSource,而是使用了一个连接并释放了它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36745911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档