【问题标题】:JNDI issue with weblogic + spring + eclipselinkweblogic + spring + eclipselink 的 JNDI 问题
【发布时间】:2012-08-09 11:51:12
【问题描述】:

我在 Spring 3.0 中有一个使用 eclipselink 作为持久性提供程序的应用程序。该应用程序在 Jetty 应用服务器中运行良好,但在 weblogic 中部署时出现错误。必要的细节如下

Spring xml 文件

   <context:property-placeholder location="classpath:jdbc.properties"
    ignore-unresolvable="true" />
    <jee:jndi-lookup id="jndiDataSource" jndi-name="${jndi.name}"
    resource-ref="true" />

<bean id="pum"
    class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="persistenceXmlLocations">
        <list>
            <value>classpath*:META-INF/persistence.xml</value>
        </list>
    </property>
    <property name="defaultDataSource" ref="jndiDataSource" />
</bean>
        <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="my-persistence" />
    <property name="persistenceUnitManager" ref="pum" />
    <property name="jpaDialect" ref="jpaDialect" />
    <property name="jpaVendorAdapter" ref="jpaAdapter" />
    <property name="loadTimeWeaver" ref="loadTimeWeaver" />
</bean>

<bean id="jpaAdapter"
    class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
    p:databasePlatform="${toplink.database.platform}" p:showSql="true" />

<bean id="jpaDialect"
    class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />

属性文件如下

         jdbc.driverClassName=org.postgresql.Driver
         jdbc.url=jdbc:postgresql://localhost:5432/myDB
         jdbc.username=***
         jdbc.password=***

         jndi.name=jndi/myDBjndi
         jndi.resourceRef=true
          jndi.enabled=true

        hibernate.database.platform=org.hibernate.dialect.PostgreSQLDialect
    toplink.database.platform=org.eclipse.persistence.platform.database.PostgreSQLPlatform    

我已经在 web.xml 中声明了一个标签

            <resource-ref>
    <descriptionMy DataSource Reference</description>
    <res-ref-name>jndi/myDBjndi</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>      

以上在 Jetty 中有效,但在 Weblogic 10.3.4 中我得到以下异常

        ####<Aug 9, 2012 6:19:46 PM CST> <Info> <EclipseLink>  <AdminServer> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <f637fb3f44bc7f84:-2787ac98:1390ae3403e:-8000-000000000000001e> <1344507586988> <BEA-2005000> <2012-08-09 18:19:46.988--ServerSession(57821834)--Connection(55507026)--connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> ""
datasource URL=> "null"))> 
        ####<Aug 9, 2012 6:19:47 PM CST> <Alert> <EclipseLink> <AdminServer> <  [ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <f637fb3f44bc7f84:-2787ac98:1390ae3403e:-8000-000000000000001e> <1344507587003> <BEA-2005000> <2012-08-09 18:19:47.003--ServerSession(57821834)--Local Exception Stack: 
               Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): 
            org.eclipse.persistence.exceptions.DatabaseException
            Exception Description: Unable to acquire a connection from driver [null], user  [null] and URL [null].  Verify that you have set the expected driver class and URL.  Check your login, persistence.xml or sessions.xml resource.  The jdbc.driver property should be set to a class that is compatible with your database platform
               at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:376)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:91)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:330)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:293)

知道我做错了什么吗?

【问题讨论】:

  • 数据源是否已在 weblogic 服务器中定义并运行良好?
  • 是的。我检查了 weblogic 服务器中的 JNDI,它工作正常。
  • 只是为了更新。我将persistence.xml 的名称更改为其他名称,这似乎解决了问题。虽然不知道确切的原因。

标签: spring weblogic eclipselink jndi


【解决方案1】:

这是因为像 weblogic 这样的 Java EE 容器会自动检测在 /META-INF 文件夹中分配的 persistence.xml 文件并预加载 Persistence Unit(使用内置实现),但不知道在休眠时设置的 JPA 属性等级。持久性单元只能由Spring 引导,因此将文件重命名为其他名称可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    相关资源
    最近更新 更多