Java spring持久性错误创建bean

时间:2013-08-27 19:35:59

标签: java spring jdbc persistence jndi

我正在尝试设置一个开源产品,得到这个错误,无法弄清楚这是什么(不是java程序员)。将不胜感激任何意见。

    2013-08-27 19:15:32,791 - ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'payoutStructureServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.f
actory.BeanCreationException: Could not autowire field: private com.cubeia.games.poker.admin.db.AdminDAO com.cubeia.games.poker.admin.service.PayoutStructureServiceImpl.adminDAO; nested exception is org.sprin
gframework.beans.factory.BeanCreationException: Error creating bean with name 'adminDAO' defined in class path resource [spring-app.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting
bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-a
pp.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: adminPersistenceUnit] Unable to build EntityManagerFactory
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:411)
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:247)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)
        at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:293)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
        at org.eclipse.jetty.server.Server.doStart(Server.java:277)
        at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
        at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
        at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:516)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)

在spring-app.xml中我有

<!-- DataSource -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="jndi.dataSource"/>
    <property name="persistenceUnitName" value="adminPersistenceUnit"/>
    <property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
    <property name="jpaVendorAdapter">
       <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
           <property name="showSql" value="true" />
           <property name="generateDdl" value="true" />
           <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
       </bean>
    </property>
</bean>

在persistence.xml中我有

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
   version="1.0">

   <persistence-unit name="adminPersistenceUnit" transaction-type="RESOURCE_LOCAL">
       <class>com.cubeia.games.poker.tournament.configuration.payouts.PayoutStructure</class>
       <class>com.cubeia.games.poker.tournament.configuration.payouts.Payouts</class>
       <class>com.cubeia.games.poker.tournament.configuration.payouts.Payout</class>
       <class>com.cubeia.games.poker.tournament.configuration.payouts.IntRange</class>
       <class>com.cubeia.games.poker.tournament.configuration.blinds.BlindsStructure</class>
       <class>com.cubeia.games.poker.tournament.configuration.blinds.Level</class>
       <class>com.cubeia.games.poker.tournament.configuration.TournamentSchedule</class>
       <class>com.cubeia.games.poker.tournament.configuration.ScheduledTournamentConfiguration</class>
       <class>com.cubeia.games.poker.tournament.configuration.SitAndGoConfiguration</class>
       <class>com.cubeia.games.poker.tournament.configuration.TournamentConfiguration</class>
       <class>com.cubeia.games.poker.tournament.configuration.RebuyConfiguration</class>
       <class>com.cubeia.games.poker.entity.TableConfigTemplate</class>
       <class>com.cubeia.poker.timing.TimingProfile</class>
       <class>com.cubeia.poker.settings.RakeSettings</class>


       <properties>
        <!-- property name="hibernate.hbm2ddl.auto" value="create-drop"/-->
      </properties>
   </persistence-unit>
</persistence>

有趣的是,如果我从jetty-env.xml中切换到MySQL并配置本地或远程数据库,应用程序崩溃说JDBC超时错误,这是不可能的,整个基础架构是A类,没有错误,超时或任何东西,可以SSH / Telnet / mysql进入服务器没有问题。实际上对于localhost也是如此。有一种预感,这实际上是与上述内容相关的错误,而不是真正的连接问题(感谢java的默默无闻)

非常感谢任何意见/建议。谢谢!

1 个答案:

答案 0 :(得分:0)

事实证明代码存在问题,类中的一些更改未通过使用隐式数据库表的其余代码传播。

在提交之前分叉之后,错误完全消失了。

broken code here

this helped

似乎这在某种程度上也与hibernate实现中的一个bug有关,用一些注释摆脱它