users@glassfish.java.net

Spring 2 AOP and Glassfish

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Sep 2007 12:10:04 PDT

Hi!,
I am running into a problem using Spring 2 AOP and GlassFish. Briefly, I have a GlassFish web service that uses a Spring bean. Spring aspects are invoked before this bean. When I try to invoke this web service which in turn invokes the Spring 2 bean and aspects (the aspect is configured using Spring 2 AOP and Spring XML configuration style) the following exception is thrown (stack trace follows):

javax.servlet.ServletException
        at com.sun.enterprise.webservice.JAXWSServlet.doInit(JAXWSServlet.java:260)
        at com.sun.enterprise.webservice.JAXWSServlet.init(JAXWSServlet.java:113)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1178)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:832)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
        at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: javax.xml.ws.WebServiceException: com.sun.enterprise.InjectionException: Exception attempting invoke lifecycle method private void webservice.ATM.init()
        at com.sun.enterprise.webservice.ResourceInjectorImpl.inject(ResourceInjectorImpl.java:119)
        at com.sun.enterprise.webservice.InstanceResolverImpl.start(InstanceResolverImpl.java:79)
        at com.sun.enterprise.webservice.InstanceResolverImpl$1.start(InstanceResolverImpl.java:102)
        at com.sun.xml.ws.server.InvokerTube.setEndpoint(InvokerTube.java:80)
        at com.sun.xml.ws.server.WSEndpointImpl.<init>(WSEndpointImpl.java:163)
        at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:217)
        at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
        at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:510)
        at com.sun.enterprise.webservice.JAXWSServlet.registerEndpoint(JAXWSServlet.java:398)
        at com.sun.enterprise.webservice.JAXWSServlet.doInit(JAXWSServlet.java:252)
        ... 29 more
Caused by: com.sun.enterprise.InjectionException: Exception attempting invoke lifecycle method private void webservice.ATM.init()
        at com.sun.enterprise.util.InjectionManagerImpl.invokeLifecycleMethod(InjectionManagerImpl.java:426)
        at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:230)
        at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:100)
        at com.sun.enterprise.webservice.ResourceInjectorImpl.inject(ResourceInjectorImpl.java:84)
        ... 38 more
Caused by: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.enterprise.util.InjectionManagerImpl.invokeLifecycleMethod(InjectionManagerImpl.java:411)
        ... 41 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.util.InjectionManagerImpl$3.run(InjectionManagerImpl.java:417)
        ... 43 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor': Cannot create inner bean '(inner bean)' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer$AmbiguousBindingException: Found 2 candidate variable names but only one candidate binding slot when matching primitive args
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:205)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:116)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:955)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:729)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:416)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
        at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102)
        at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:68)
        at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:54)
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:247)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:311)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1038)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
        at webservice.ATM.init(Unknown Source)
        ... 48 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Invocation of init method failed; nested exception is org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer$AmbiguousBindingException: Found 2 candidate variable names but only one candidate binding slot when matching primitive args
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1032)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:198)
        ... 73 more
Caused by: org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer$AmbiguousBindingException: Found 2 candidate variable names but only one candidate binding slot when matching primitive args
        at org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.maybeBindPrimitiveArgsFromPointcutExpression(AspectJAdviceParameterNameDiscoverer.java:597)
        at org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.getParameterNames(AspectJAdviceParameterNameDiscoverer.java:235)
        at org.springframework.core.PrioritizedParameterNameDiscoverer.getParameterNames(PrioritizedParameterNameDiscoverer.java:54)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.bindArgumentsByName(AbstractAspectJAdvice.java:370)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.calculateArgumentBindings(AbstractAspectJAdvice.java:331)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.afterPropertiesSet(AbstractAspectJAdvice.java:297)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
        ... 75 more

The same Spring 2 bean (and aspect) works fine when run from a standalone JVM!! The Spring 2 JARs are bundled within the application WAR and security is turned off. An abbreviated version of the Spring 2 xml config file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

  <!-- ATM bean implementation -->
  <bean id="atmBean" class="beans.atm.SimpleATMService"/>

  <!-- Audit aspect bean -->
  <bean id="auditor" class="util.Auditor"/>

  <!-- Aspects for beans -->
  <aop:config>
    <aop:aspect ref="auditor">
      <aop:pointcut
        id="depositMethodBefore"
        expression="execution(* beans.atm.ATMService.depositFunds(String,float))
        and args(accountNumber, amount)" />
      <aop:before
        pointcut-ref="depositMethodBefore"
        method="auditDeposit"/>
    </aop:aspect>
  </aop:config>
</beans>


NOTE: when the aspect is not used the web service (with the Spring 2 bean and no Spring 2 aspects) works fine!

Is there some other requirement that I am missing for enabling Spring 2 AOP support on GlassFish (JARs in app server classpath, delegation turned off, etc.)?
[Message sent by forum member 'klee1703' (klee1703)]

http://forums.java.net/jive/thread.jspa?messageID=235896