This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Than... Struts 2 + Spring 3.1 without hibernate runs.... Spring 3.1 + Hibernate 3.1 without Struts 2 LIKE an application (with main method) runs... if I try to run everything together I have always a java.lang.classnotfound.exception

Removing this two bean and doing a simple Syso on the service class (the workflow is action->businnesDelegate->SessionFacade->Services) and adding the follow libraries in WebInf/lib, struts2 + Spring 3.1 works fine!! The jars are:

Re-adding the two beans and running the all project like an application it's read and write on db correctly.
But if I try to run all on the server (Tomcat 6.0) nothing works! I try to add a lot of version of cglib.jar, cglib-nodep, a lot of version of asm, spring-orm, spring-hibernate, but every time appear a different java.lang.classNotFoundException... I'm really going mad.

Dont put more than one version of a jar on the classpath. The results will not be predictable. You just have to find the config that works.

I struggled with this initially as well, I think the Spring binary distribution does not include everything. I had to track down a few things. Here is what works for me, spring wise, I cannot speak for struts2 or hibernate.

As already mentioned use a single verison of spring you are mixing 2 version 3.0 and 3.1, don't. You are also mixing 2 different versions of ASM and 2 versions of commons-logging again don't...

Also if you are still managing your dependencies yourself I strongly suggest step into the real world and use either ant+ivy, maven or gradle to manage your dependencies (it will probably give you some other headaches but in general it saves you a lot of time).

Also you are using hibernate and there is no spring-orm jar nor hibernate jar.

A final note don't use HibernateDaoSupport and/or HibernateTemplate they should be considered deprecated as of Hibernate 3.0.1 (which appeared somewhere in 2007).

Comment

Yes Marten you're right but the version of spring is just one! Is just a copy-paste error! I have clean my webinf/lib and I have added all the spring 3.1 library. Than I have added from Hibernate 3.1 library folder the follow libs:
antlr-2.7.6rc1
asm.jar (I have tried 3.3.1 and doesn't work)
cglib-2.1.3 (I have tried 2.2 and doesn't work)
commons-collections-2.1.1
commons-logging-1.0.4 (I have tried the 1.1.1 and doesn't work)
dom4j-1.6.1
ehcahce-1.1
hibernate3
jta

Than I downloaded the libs you suggest to me: aspectjrt and aspectjweaver com.springsource.org.aopalliance-1.0.0 (from spring site)

If I deploy everything I receive this error:

Code:

GRAVE: CGLIB Enhancement failed: it.almawave.crm.dto.LoginDTO
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)

And after this another exception:

Code:

Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 55 more
17-feb-2012 10.37.35 org.hibernate.tuple.PojoEntityTuplizer buildProxyFactory
AVVERTENZA: could not create proxy factory for:it.almawave.crm.dto.LoginDTO
org.hibernate.HibernateException: CGLIB Enhancement failed: it.almawave.crm.dto.LoginDTO
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:132)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)

And te last one:

Code:

Caused by: java.lang.NoClassDefFoundError: org/springframework/orm/hibernate3/support/HibernateDaoSupport
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)

As mentioned don't hack around yourself use something as Ant+ivy, Gradle or Maven to manage your dependencies...

You seem to be missing the spring-orm library in your WEB-INF/lib directory als again don't mix different versions of libraries (commons-logging 1.1.1 is required, next to that as suggest before use something to manage your dependencies instead of trying to google and download yourself).

So you have time to scavenge the internet hunting for (sometimes obscure) jars where using maven would have saved you that time... Hmm sounds logical to me...

Anyway your errors indicate missing jars and maybe the use of final classes, also you should use the cglib-nodep jar (version 2.2.2 is the most recent). Also you probably need to upgrade your hibernate as Spring 3.1 targets hibernate 3.5 and up if I'm not mistaken.