0

我有一个简单的 Web 应用程序,我正在尝试运行它并且遇到了问题。我将 Java EE 6 应用程序迁移到 Spring。似乎休眠开始正常,但是当 Spring 尝试创建一个引用实体的命名 bean 时,我得到 ClassNotFoundException。

任何想法为什么春天没有看到WAR的WEB-INF / lib中的jar?我有某种代理问题吗?

让我知道您希望查看哪些文件的片段(如果有)。

编辑:附加堆栈跟踪-为简洁起见,我在堆栈跟踪中修改了完全限定的类名。我还附上了我的 spring bean 配置。另外,仅供参考,我的实体类都在不同的 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>

谢谢,

沃尔特

4

1 回答 1

0

我想通了,我必须在我的 persistence.xml 中指定指向外部罐子。

沃尔特

于 2013-03-04T20:19:35.863 回答