0
我有一個簡單的web應用程序,我試圖運行並遇到問題。我將Java EE 6應用程序遷移到Spring。看來hibernate開始很好,但是當Spring試圖創建一個指向實體的命名bean時,我得到了ClassNotFoundException。spring + hibernate class not found
任何想法爲什麼在WAR的WEB-INF/lib中的jar沒有被spring看到?我有某種代理問題?
讓我知道你想看到什麼文件的片段,如果有的話。
編輯:附加堆棧跟蹤 - 我修改了堆棧跟蹤中的全限定類名稱以簡化操作。我還附加了我的彈簧豆配置。此外,FYI,我的實體類都在不同的jar文件(按設計)。我相信這是造成一些問題,但我不知道爲什麼。
n]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: api/model/principal/Group
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1011)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:957)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [server.administration.GroupExampleBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: api/model/principal/Group
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
... 23 more
Caused by: java.lang.NoClassDefFoundError: api/model/principal/Group
at server.administration.GroupExampleBean.<init>(GroupExampleBean.java:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 25 more
Caused by: java.lang.ClassNotFoundException: api.model.principal.Group
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
... 31 more
我的Spring應用程序上下文:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jpa="http://www.springframework.org/schema/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jpa
http://www.springframework.org/schema/jpa/spring-jpa-3.2.xsd">
<jpa:repositories base-package="examples" />
<context:component-scan base-package="examples"/>
<context:annotation-config/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="database" value="HSQL" />
<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
</bean>
</property>
<property name="persistenceUnitName" value="persistenceUnit" />
</bean>
<bean id="transactionMa## Heading ##nager" class="org.springframework.orm.jpa.JpaTransactionManager">
<!--<property name="entityManagerFactory" ref="entityManagerFactory"/>-->
</bean>
<!--
can be: HSQL/H2/Derby
-->
<jdbc:embedded-database id="dataSource" type="HSQL"/>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- For some reason the annotations are not being picked up yet -->
<!--<bean id="startupListener" class="examples.web.application.StartupListener"/>-->
<!-- Spring will manage the JPA Listeners
<jpa:auditing auditor-aware-ref="auditorAware" />
<bean id="auditorAware" class="org.springframework.data.jpa.example.auditing.AuditorAwareImpl" />
-->
<!--
<jpa:repositories base-package="org.springframework.data.jpa.example.repository.simple" />
-->
</beans>
感謝,
沃爾特
檢查,看看是否WEB-INF/lib目錄中的內容被捆綁到你的戰爭或移動到您從開始展開的目錄。 – duffymo 2013-02-25 20:11:10
什麼是完整的堆棧跟蹤和錯誤消息?通常這個消息告訴你哪個類找不到。 – beny23 2013-02-25 20:16:50
我已經檢查過WAR文件,它們在那裏。然而,在查看了hibernate的日誌之後,由於檢測註釋類的啓動時間是0ms,所以它沒有出現hibernate檢測到的任何實體。我沒有進一步檢查休眠。 – Walter 2013-02-25 20:31:44