Note that there are some explanatory texts on larger screens.

plurals
  1. POspring + hibernate class not found
    text
    copied!<p>I have a simple web application that I am trying to get running and am having problems. I migrated a Java EE 6 application to Spring. It appears hibernate starts fine, but when Spring attempts to create a named bean that refers to an entity, I get ClassNotFoundException.</p> <p>Any ideas why a jar inside WEB-INF/lib of the WAR is not being seen by spring? Am I having some sort of proxying issue?</p> <p>Let me know what files you would like to see snippets of, if any.</p> <p>EDIT: stack trace attached - I modified the fully qualified class names, in the stack trace for brevity. I also attached my spring beans configuration. Also, FYI, my entity classes are all in different jar files (by design). I believe that is causing some problems, but am not sure why.</p> <pre><code>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.&lt;init&gt;(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 </code></pre> <p>My Spring application context:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;jpa:repositories base-package="examples" /&gt; &lt;context:component-scan base-package="examples"/&gt; &lt;context:annotation-config/&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource"/&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;property name="database" value="HSQL" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="persistenceUnitName" value="persistenceUnit" /&gt; &lt;/bean&gt; &lt;bean id="transactionMa## Heading ##nager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;!--&lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;--&gt; &lt;/bean&gt; &lt;!-- can be: HSQL/H2/Derby --&gt; &lt;jdbc:embedded-database id="dataSource" type="HSQL"/&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;!-- For some reason the annotations are not being picked up yet --&gt; &lt;!--&lt;bean id="startupListener" class="examples.web.application.StartupListener"/&gt;--&gt; &lt;!-- Spring will manage the JPA Listeners &lt;jpa:auditing auditor-aware-ref="auditorAware" /&gt; &lt;bean id="auditorAware" class="org.springframework.data.jpa.example.auditing.AuditorAwareImpl" /&gt; --&gt; &lt;!-- &lt;jpa:repositories base-package="org.springframework.data.jpa.example.repository.simple" /&gt; --&gt; &lt;/beans&gt; </code></pre> <p>Thanks,</p> <p>Walter</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload