Announcement Announcement Module
Collapse
No announcement yet.
Struts2 (tomcat 6.0) + Spring 3.1 + Hibernate 3.1 damned issue!! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Struts2 (tomcat 6.0) + Spring 3.1 + Hibernate 3.1 damned issue!!

    Hi All and thanks in advance.
    I'm new here, and since 3 days I tried to run a damned 3 level architecture web application! I try to describe my app:

    core level: Java project, here I have spring 3.1 + Hibernate 3.1 libraries - DAO, session facade, services .java files.

    model level: Java project, here I have *.hbm.xml file and the config file of hibernate - DTO(pojo) and VO .java files

    web level: Dinamic Web Project, here I have Struts 2.1.8 libraries - action and businnes delegate .java files

    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

    in the web.xml I have add:
    Code:
    ...
    <context-param>
      	<param-name>contextConfigLocation</param-name>
      	<param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
      	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    ...
    An example of my DAO class:
    Code:
    public class LoginDAO extends HibernateDaoSupport {
    	
    	public LoginDAO() {}
    	
    	public List<LoginDTO> findAll() {
    		return getHibernateTemplate().find("from user");		
    	}
    
    }
    the relative spring beans are:
    Code:
    <bean id="DAO" class="it.almawave.crm.dao.LoginDAO">
    	<property name="sessionFactory" ref="SessionFactory"></property>
    </bean>
    
    <bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    	<property name="hibernateProperties">
    		<props>
    			<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    			<!-- <prop key="hibernate.show_sql">true</prop> -->
    			<prop key="hibernate.hbm2ddl.auto">update</prop>
    			<prop key="hibernate.connection.autocommit">true</prop>
    		</props>
    	</property>
    	<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
    </bean>
    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:

    antlr-2.7.2.jar
    antlr-3.0.1.jar
    commons-fileupload-1.2.1.jar
    commons-logging-1.0.4.jar
    commons-logging-api-1.1.jar
    freemarker-2.3.15.jar
    org.springframework.asm-3.1.0.RELEASE.jar
    org.springframework.beans-3.0.0.M3.jar
    org.springframework.context-3.0.0.M3.jar
    org.springframework.core-3.0.0.M3.jar
    org.springframework.expression-3.0.0.M3.jar
    org.springframework.transaction-3.1.0.RELEASE.jar
    org.springframework.web-3.0.0.M3.jar
    struts2-core-2.1.8.jar
    struts2-spring-plugin-2.1.8.jar
    xwork-core-2.1.6.jar

    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.

    Please help me.

    Thank you all.

  • #2
    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.

    asm-3.3.1.jar
    aspectjrt.jar
    aspectjweaver.jar
    cglib-2.2.jar
    com.springsource.org.aopalliance-1.0.0.jar
    org.springframework.aop-3.0.5.RELEASE.jar
    org.springframework.asm-3.0.5.RELEASE.jar
    org.springframework.aspects-3.0.5.RELEASE.jar
    org.springframework.beans-3.0.5.RELEASE.jar
    org.springframework.context-3.0.5.RELEASE.jar
    org.springframework.context.support-3.0.5.RELEASE.jar
    org.springframework.core-3.0.5.RELEASE.jar
    org.springframework.expression-3.0.5.RELEASE.jar
    org.springframework.instrument-3.0.5.RELEASE.jar
    org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
    org.springframework.jdbc-3.0.5.RELEASE.jar
    org.springframework.jms-3.0.5.RELEASE.jar
    org.springframework.orm-3.0.5.RELEASE.jar
    org.springframework.oxm-3.0.5.RELEASE.jar
    org.springframework.spring-library-3.0.5.RELEASE.libd
    org.springframework.test-3.0.5.RELEASE.jar
    org.springframework.transaction-3.0.5.RELEASE.jar
    org.springframework.web-3.0.5.RELEASE.jar
    org.springframework.web.portlet-3.0.5.RELEASE.jar
    org.springframework.web.servlet-3.0.5.RELEASE.jar
    org.springframework.web.struts-3.0.5.RELEASE.jar

    Comment


    • #3
      Also commons-logging-1.1.1.jar

      Comment


      • #4
        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


        • #5
          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)
          With my spring.orm.jar inside the classpath..

          I don't know what I have to do..

          Thanks All

          Comment


          • #6
            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).

            Comment


            • #7
              I can use maven right now.. thanks anyway..

              Comment


              • #8
                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.

                Comment

                Working...
                X