Announcement Announcement Module
Collapse
No announcement yet.
Dependency Injection in JPA Entity Listener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dependency Injection in JPA Entity Listener

    Hi,

    I have a JPA Entity Listener attached to my domain objects and I am trying to inject a service into the Entity Listener and I am having problems.

    I am using

    Glassfish 3
    Spring 3.0.4
    aspectjweaver 1.6.9

    My config is as follows:

    <context:annotation-config/>
    <context:spring-configured/>
    <context:load-time-weaver />

    <bean class="audit.AuditListener"/>
    <bean class="TestService"/>
    My AuditListener is declared as:

    @Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true)
    public class AuditListener {
    @Autowired
    private TestService testService;
    ...
    I have added the following to my Glassfish configuration script

    <jvm-options>-javaagent:${com.sun.aas.instanceRoot}/lib/spring-agent-2.5.6.jar</jvm-options>
    where the agent jar file exists in that location.

    And added the following to my context.xml (I read a blog which says I need this if I am using a WAR and not an EAR)

    <Loader
    loaderClass="org.springframework.instrument.classl oading.glassfish.GlassFishLoadTimeWeaver"
    useSystemClassLoaderAsParent="false"/>
    I get the following error: (too big for post - will add it next)


    I do not know if I am mixing and matching the wrong configuration for different things here. Maybe someone could help clear up if I am actually going about this the right way for what I described above.

    Thanks

    Chris

  • #2
    error as above.

    [#|2010-12-09T16:16:24.371+0000|SEVERE|glassfish3.0.1|org.asp ectj.weaver.loadtime.Aj|_ThreadID=29;_ThreadName=T hread-1;|org/springframework/transaction/aspectj/AbstractTransactionAspect
    java.lang.RuntimeException: Problem processing attributes in org.springframework.transaction.aspectj.AbstractTr ansactionAspect
    at org.aspectj.weaver.bcel.BcelObjectType.ensureAspec tJAttributesUnpacked(BcelObjectType.java:383)
    at org.aspectj.weaver.bcel.BcelObjectType.<init>(Bcel ObjectType.java:160)
    at org.aspectj.weaver.bcel.BcelWorld.buildBcelDelegat e(BcelWorld.java:382)
    at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectT ype(BcelWorld.java:516)
    at org.aspectj.weaver.tools.WeavingAdaptor.ensureDele gateInitialized(WeavingAdaptor.java:453)
    at org.aspectj.weaver.tools.WeavingAdaptor$WeavingCla ssFileProvider.<init>(WeavingAdaptor.java:784)
    at org.aspectj.weaver.tools.WeavingAdaptor.getWovenBy tes(WeavingAdaptor.java:466)
    at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass (WeavingAdaptor.java:318)
    at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java: 96)
    at org.aspectj.weaver.loadtime.ClassPreProcessorAgent Adapter.transform(ClassPreProcessorAgentAdapter.ja va:54)
    at org.springframework.context.weaving.AspectJWeaving Enabler$AspectJClassBypassingClassFileTransformer. transform(AspectJWeavingEnabler.java:97)
    at org.glassfish.web.loader.WebappClassLoader$3.prepr ocess(WebappClassLoader.java:2685)
    at org.glassfish.web.loader.WebappClassLoader.findCla ss(WebappClassLoader.java:916)
    at org.glassfish.web.loader.WebappClassLoader.loadCla ss(WebappClassLoader.java:1430)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Cla ss.java:2389)
    at java.lang.Class.getDeclaredConstructors(Class.java :1836)
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.determineCandidate Constructors(AutowiredAnnotationBeanPostProcessor. java:228)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.determineConstructorsFr omBeanPostProcessors(AbstractAutowireCapableBeanFa ctory.java:930)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:903)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.findAutowireCandidates(DefaultL istableBeanFactory.java:844)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.doResolveDependency(DefaultList ableBeanFactory.java:786)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.resolveDependency(DefaultListab leBeanFactory.java:703)
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:478)
    at org.springframework.beans.factory.annotation.Injec tionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessPropert yValues(AutowiredAnnotationBeanPostProcessor.java: 283)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1074)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 47)
    at org.apache.catalina.core.StandardContext.contextLi stenerStart(StandardContext.java:4664)
    at com.sun.enterprise.web.WebModule.contextListenerSt art(WebModule.java:535)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:5266)
    at com.sun.enterprise.web.WebModule.start(WebModule.j ava:499)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:928)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:912)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:694)
    at com.sun.enterprise.web.WebContainer.loadWebModule( WebContainer.java:1947)
    at com.sun.enterprise.web.WebContainer.loadWebModule
    ....

    Comment


    • #3
      I am still having problems trying to figure this out.

      Can anyone explain what the correct steps are to enable dependency injection into a JPA EntityListener on Glassfish. I have tried mixing and matching these but nothing.

      thanks.

      Comment

      Working...
      X