运行Spring + Eclipse Link jpa应用程序时不会释放数据库连接

时间:2016-10-20 09:51:15

标签: java spring jpa eclipselink

以下是persistence.xml配置。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="Associateinfo">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.testpackage.associateinfo.model.Associate</class>


    <properties>
      <property name="eclipselink.logging.level" value="FINE"/>
      <property name="eclipselink.logging.exceptions" value="true"/>
      <property name="eclipselink.logging.timestamp" value="true" />
      <property name="eclipselink.logging.session" value="true" />
      <property name="eclipselink.logging.thread" value="true" />
      <property name="eclipselink.logging.connection" value="true"/>

      <property name="eclipselink.target-database" value="SQLServer" />
      <property name="eclipselink.ddl-generation.output-mode" value="both"/>

      <property name="eclipselink.weaving" value="false"/>
      <property name="eclipselink.flush-clear.cache" value="DropInvalidate"/>


      <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>

      <property name="javax.persistence.jdbc.url" value="test"/>
      <property name="javax.persistence.jdbc.user" value="uname"/>
      <property name="javax.persistence.jdbc.password" value="pwd"/>
      <property name="eclipselink.logging.connection" value="true"/>
      <property name="eclipselink.cache.size.default" value="20000"/>
      <property name="eclipselink.query-results-cache" value="true"/>

    </properties>
  </persistence-unit>
</persistence>

弹簧配置:

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

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static 
        resources in the ${webappRoot}/resources directory -->
    <mvc:resources
        mapping="/resources/**"
        location="/resources/" />

    <beans:import resource="view.xml" />

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

    <!-- Application properties --> 
    <bean name="appProperties" 
       class="org.springframework.beans.factory.config.MapFactoryBean">
       <property name="sourceMap">
          <map>
             <entry key="useMinifiedScript" value="false" />
          </map>
       </property>
    </bean>   

    <bean
        id="persistenceExceptionInterceptor"
        class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
    <jpa:repositories
        base-package="com.testpackage.associateinfo.dao"
        query-lookup-strategy="use-declared-query" />

    <!-- -->
    <!-- This will ensure that JPA exceptions are automatically translated into Spring's 
        generic DataAccessException hierarchy for those classes annotated with @Repository. -->
    <bean
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <!-- JPA Entity Manager Factory -->
    <bean
        id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"

        p:persistenceXmlLocation="classpath:META-INF/persistence.xml"
        p:persistenceUnitName="Associateinfo">

        <property name="persistenceUnitManager">
         <bean class="org.springframework.data.jpa.support.MergingPersistenceUnitManager" />
      </property>
        <property name="jpaPropertyMap">
            <map>
                <entry
                    key="eclipselink.weaving"
                    value="false" />
            </map>
        </property>
    </bean>

    <!-- bean post-processor for JPA annotations -->
    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />


    <!-- Transaction configuration -->
    <bean
        id="transactionManager"
        class="org.springframework.orm.jpa.JpaTransactionManager"
        p:entityManagerFactory-ref="entityManagerFactory" />

    <!-- use declarative transaction management -->
    <tx:annotation-driven transaction-manager="transactionManager" />



</beans:beans>

运行此应用程序后,几天后我看到数据库端打开了数据库连接,在Jboss服务器上运行的应用程序端获得连接关闭异常。     如果我错过任何配置,请帮助我。

0 个答案:

没有答案