Announcement Announcement Module
Collapse
No announcement yet.
Eclipselink with Spring 2.5x - Issues running with Jetty Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Eclipselink with Spring 2.5x - Issues running with Jetty

    Hi Spring Gurus.

    I'm attempting to leverage EclipseLink in combination with Spring 2.5 using J2SE (via Jetty server). I've adapted the petclinic/eclipselink sample found at http://blog.springsource.com/main/20...ation-platform.


    When I start maven jetty:run with the following set:
    set MAVEN_OPTS=-javaagent:"C:\Documents and Settings\Administrator\.m2\repository\org\springfr amework\spring-agent\2.5.4\spring-agent-2.5.4.jar"

    It bombs out with exception due to the following line:
    <context:load-time-weaver aspectj-weaving="on"/>

    It fails stating that

    2008-08-13 01:11:52.111:/:INFO: Initializing Spring root WebApplicationContext
    (16 ms) [main] ERROR: org.springframework.web.context.ContextLoader#init WebApplicationContext : Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavin gEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.mortbay.jetty.webapp.WebAppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:478)
    ...


    If i change the line to be <context:load-time-weaver aspectj-weaving="on" weaver-class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />

    It gives the error

    java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.


    If i comment the line out entirely... I get the error

    [EL Config]: 2008.08.13 01:17:38.796--ServerSession(15703940)--Thread(Thread[main,5,main])--The alias name for the entity class [class org.springframework.petclinic.domain.PetType] is being defaulted to: PetType.
    [EL Config]: 2008.08.13 01:17:38.843--ServerSession(15703940)--Thread(Thread[main,5,main])--The column name for element
    [private java.lang.String org.springframework.petclinic.domain.NamedEntity.n ame] is being defaulted to: NAME.
    [EL Config]: 2008.08.13 01:17:38.843--ServerSession(15703940)--Thread(Thread[main,5,main])--The column name for element
    [private java.lang.Integer org.springframework.petclinic.domain.BaseEntity.id] is being defaulted to: ID.
    (15 ms) [main] ERROR: org.springframework.web.context.ContextLoader#init WebApplicationContext : Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/applicationContext-persistence.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption:
    Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext-persistence.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception
    [EclipseLink-28018] (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)): org.eclipse.persistence.exceptions.EntityManagerSe tupException
    Exception Description: Predeployment of PersistenceUnit [PetClinic] failed.
    Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)): org.eclipse.persistence.exceptions.ValidationExcep tion
    Exception Description: Entity class [class org.springframework.petclinic.domain.PetType] has no primary key specified. It
    should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then please make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:478)


    I would be greateful if anyone can take a quick look and see if they can work out how to get past any of these exceptions. I've got a bad feeling i may have to leverage a full j2ee container.

    thanks

    Matt.
    Last edited by mshannon; Aug 13th, 2008, 11:59 AM. Reason: invalid url

  • #2
    There seem's to be many people out there unable to run maven / jetty with javaagent. If i deploy the war to OC4J, and start oc4j with the javaagent parameter, it works perfectly.

    Originally posted by mshannon View Post
    When I start maven jetty:run with the following set:
    set MAVEN_OPTS=-javaagent:"C:\Documents and Settings\Administrator\.m2\repository\org\springfr amework\spring-agent\2.5.4\spring-agent-2.5.4.jar"

    It bombs out with exception due to the following line:
    <context:load-time-weaver aspectj-weaving="on"/>

    It fails stating that

    2008-08-13 01:11:52.111:/:INFO: Initializing Spring root WebApplicationContext
    (16 ms) [main] ERROR: org.springframework.web.context.ContextLoader#init WebApplicationContext : Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavin gEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.mortbay.jetty.webapp.WebAppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:478)
    ...


    If i change the line to be <context:load-time-weaver aspectj-weaving="on" weaver-class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />

    It gives the error

    java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.



    The issue below is resolved with 1.0.1 of eclipselink
    Originally posted by mshannon View Post

    If i comment the line out entirely... I get the error

    [EL Config]: 2008.08.13 01:17:38.796--ServerSession(15703940)--Thread(Thread[main,5,main])--The alias name for the entity class [class org.springframework.petclinic.domain.PetType] is being defaulted to: PetType.
    [EL Config]: 2008.08.13 01:17:38.843--ServerSession(15703940)--Thread(Thread[main,5,main])--The column name for element
    [private java.lang.String org.springframework.petclinic.domain.NamedEntity.n ame] is being defaulted to: NAME.
    [EL Config]: 2008.08.13 01:17:38.843--ServerSession(15703940)--Thread(Thread[main,5,main])--The column name for element
    [private java.lang.Integer org.springframework.petclinic.domain.BaseEntity.id] is being defaulted to: ID.
    (15 ms) [main] ERROR: org.springframework.web.context.ContextLoader#init WebApplicationContext : Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/applicationContext-persistence.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption:
    Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext-persistence.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception
    [EclipseLink-28018] (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)): org.eclipse.persistence.exceptions.EntityManagerSe tupException
    Exception Description: Predeployment of PersistenceUnit [PetClinic] failed.
    Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)): org.eclipse.persistence.exceptions.ValidationExcep tion
    Exception Description: Entity class [class org.springframework.petclinic.domain.PetType] has no primary key specified. It
    should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then please make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:478)
    Last edited by mshannon; Aug 13th, 2008, 11:57 AM.

    Comment


    • #3
      oc4j doesn't need the javaagent command line argument, it is in our list of supported environments (i.e. support Classweaving without an agent).

      I guess the issue here is that you start MAVEN with the javaagent NOT jetty and only using the javaagent on maven isn't doing anything. So you probably need to figure out a way to pass that property to jetty and not to maven...

      Comment


      • #4
        Hi All,

        Thanks for the tip Martin.

        Thanks to Rob Harrop - i've finally got past the issue below

        Originally posted by mshannon View Post
        Hi Spring Gurus.

        When I start maven jetty:run with the following set:
        set MAVEN_OPTS=-javaagent:"C:\Documents and Settings\Administrator\.m2\repository\org\springfr amework\spring-agent\2.5.4\spring-agent-2.5.4.jar"

        It bombs out with exception due to the following line:
        <context:load-time-weaver aspectj-weaving="on"/>

        It fails stating that

        2008-08-13 01:11:52.111:/:INFO: Initializing Spring root WebApplicationContext
        (16 ms) [main] ERROR: org.springframework.web.context.ContextLoader#init WebApplicationContext : Context initialization failed
        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavin gEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.mortbay.jetty.webapp.WebAppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:478)
        ...

        The issue I had was that there were effectively two versions of the spring agent classes on the classpath. I was starting maven with a version of the spring-agent, and also bundling the spring-agent in the war file.

        I changed my dependency on spring-agent to be provided, and now everything is working perfectly!

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-agent</artifactId>
        <version>${spring.version}</version>
        <scope>provided</scope>
        </dependency>


        Anyway - for anyone out there looking to try out eclipselink, here is a port of the S2AP Petclinic sample 1.2.0 sample, that works using Maven and the embedded Jetty plugin, along with an option to deploy to OC4J.

        petclinic_eclipselink_oc4j_and_jetty.rar

        cheers

        Matt.

        Comment


        • #5
          The example does not work for me. I am using Maven 2.0.10

          I have an issue trying to use Load Time weaving with Spring.

          With the addition of the weaving context:
          <context:load-time-weaver aspectj-weaving="on"/>


          I get this error when running :
          Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavin gEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:480)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)



          I see some posts talk about the same issue with Jetty:
          http://forum.springsource.org/archiv...p/t-58666.html


          then a fix would be to add:
          When I start maven jetty:run with the following set:
          set MAVEN_OPTS=-javaagent:"C:\Documents and Settings\Administrator\.m2\repository\org\springfr amework\spring-agent\2.5.4\spring-agent-2.5.4.jar"


          But I tried that and it does not work.

          I also have the dependency like this:
          <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-agent</artifactId>
          <version>${spring.version}</version>
          <scope>provided</scope>
          </dependency>



          Can anyone help me to get Maven to play well?

          Comment

          Working...
          X