Announcement Announcement Module
Collapse
No announcement yet.
jee:jndi-lookup and Spring AOP problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • jee:jndi-lookup and Spring AOP problem

    Hello all,

    When trying to start up a spring project that contains a Spring AOP bean and transactionality with a data source plugged as a JNDI lookup, the following error is produced:

    Code:
    ... <wrapper exceptions trimmed> ...
    Caused by: java.lang.IllegalArgumentException: error can't bind type name 'com.koutra.test.TestAspect'
    	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301) [aspectjweaver-1.7.0.jar:1.7.0]
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getFallbackPointcutExpression(AspectJExpressionPointcut.java:358) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:255) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:209) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:263) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:295) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1598) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	... 28 more
    You can see the code that causes the problem in the attached zip file. It is essentially the Spring Tool Suite template simple MVC project with an AOP bean, a service bean, and transactionality for databases added, so as to duplicate the problem. The weird thing is that when I change the data source definition in the root-context.xml from:

    Code:
    <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/protectDS" />
    to:

    Code:
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    	<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    	<property name="username" value="root"/>
    	<property name="password" value="z1g0u@l@"/>
    	<property name="url" value="jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull"/>
    </bean>
    ... all seems to be working. There is something going on with the combination of the AOP advice and the JNDI lookup of the datasource that seems to be causing the problem, but it is unclear to me what. I also tried googling for the problem, to no avail... Please provide any hints on what is going wrong here...

    I ended up writing by own version of the JndiObjectFactoryBean class that loads a one unique copy of the data source and using a bean of such concoction seems to be working, but I find it bizarre and unnatural, and I cannot believe that I am the only person that has tried Spring AOP beans with a data source that is looked up through JNDI, so I must be doing something basic wrong...

    Thank you for your time. Kind regards,

    Salagator

    P.S. Here is the attachment:
    Attachment
    Attached Files

  • #2
    Please post the aspect the problem seems to be in there (judging from the stacktrace).

    One thing that I can imagine is that it cannot determine the type so you could try and specify the proxy-interface property on the jee:jndi-lookup.

    Comment


    • #3
      The aspect in question looks like this:

      Code:
      @Aspect
      @Component
      public class TestAspect {
      	@Pointcut(value="execution(* com.koutra.test.ITestAccess.*(..))")
      	public void performSomeTest() {}
      	
      	@Around(value="com.koutra.test.TestAspect.performSomeTest()")
      	public Object performTest(ProceedingJoinPoint pjp) throws Throwable {
      		System.out.println("1");
      		
      		Object retVal = pjp.proceed();
      		
      		System.out.println("2");
      		
      		return retVal;
      	}
      }
      Where ITestAccess and TestAccess is a service interface and a dummy implementation of it just so that we have a meaningful aspect...

      And here are the contents of the root-context.xml:

      Code:
      	<aop:aspectj-autoproxy/>
      	
      	<context:component-scan base-package="com.koutra.test" />
      	
      	<bean id="testAccess" class="com.koutra.test.TestAccess" />
      	
      	<tx:annotation-driven proxy-target-class="true" />
      
      	<jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/protectDS" />
      	
      	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
      		<property name="dataSource" ref="dataSource"/>
      	</bean>
      	
      	<bean id="transactionManager"
      		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      		<property name="dataSource" ref="dataSource"/>
      	</bean>
      Hope this helps in pinpointing the problem...

      Comment


      • #4
        I have solved the very issue by setting the "lookupOnStartup" to false. Still not sure where the problem coming from though.

        Comment

        Working...
        X