Java Spring3启动时的奇数信息

Java Spring3启动时的奇数信息,java,spring,jpa,jakarta-ee,Java,Spring,Jpa,Jakarta Ee,为什么它看起来像是多次登录到我的mysql数据库 INFO: Using JTA UserTransaction: com.sun.enterprise.transaction.UserTransactionImpl@15bc8e3 INFO: Using JTA TransactionManager: com.sun.enterprise.transaction.TransactionManagerHelper@395c1d INFO: Using JTA Transactio

为什么它看起来像是多次登录到我的mysql数据库

INFO: Using JTA UserTransaction: com.sun.enterprise.transaction.UserTransactionImpl@15bc8e3
    INFO: Using JTA TransactionManager: com.sun.enterprise.transaction.TransactionManagerHelper@395c1d
    INFO: Using JTA TransactionSynchronizationRegistry: com.sun.enterprise.transaction.TransactionSynchronizationRegistryImpl@18b5862
    INFO: Root WebApplicationContext: initialization completed in 3354 ms
    INFO: WEB0671: Loading application [com.g_mavenproject1_war_1.0-SNAPSHOT] at [/]
    INFO: com._mavenproject1_war_1.0-SNAPSHOT was successfully deployed in 9,049 milliseconds.
    INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
    INFO: EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
    CONFIG: connecting(DatabaseLogin(
            platform=>MySQLPlatform
            user name=> ""
            connector=>JNDIConnector datasource name=>null
    ))
    CONFIG: Connected: jdbc:mysql://localhost:3306/florblanca
            User: root@localhost
            Database: MySQL  Version: 5.5.8
            Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
    CONFIG: connecting(DatabaseLogin(
            platform=>MySQLPlatform
            user name=> ""
            connector=>JNDIConnector datasource name=>null
    ))
    CONFIG: Connected: jdbc:mysql://localhost:3306/florblanca
            User: root@localhost
            Database: MySQL  Version: 5.5.8
            Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
    INFO: file:/C:/Users/drewh/Desktop/mavenproject1/target/mavenproject1/WEB-INF/classes/_florblancaPU login successful
    FINE: SELECT id, arrival, city, country, departure, email, guests, inserted, message, name, phone, sent, state, street, zip FROM contacts WHERE (id = ?)
            bind => [1 parameter bound]
弹簧配置:

<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:p="http://www.springframework.org/schema/p"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
">

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

    <tx:annotation-driven transaction-manager="txManager"/>

    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="florblancaPU"/>
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
                <property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform" />
                <property name="showSql" value="true" />      
            </bean>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost/florblanca"/>
        <property name="username" value="root"/>
        <property name="password" value="password"/>
    </bean>

    <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" /> 

</beans>

DriverManager数据源不维护连接池。 因此,每当您(或spring)执行“getConnection”时,它都会创建到DB的新物理连接。
要解决这个问题,请使用连接池框架(例如C3P0)。

但我使用的是实体管理器。这不是所有的艰苦工作吗?在EJB3.1中,我从来不用担心这个问题,直到您的实体管理器使用Spring配置文件中定义的DriverManager数据源对象为止。