Announcement Announcement Module
No announcement yet.
jee:jndi-lookup and Spring AOP problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    ... <wrapper exceptions trimmed> ...
    Caused by: java.lang.IllegalArgumentException: error can't bind type name 'com.koutra.test.TestAspect'
    	at [aspectjweaver-1.7.0.jar:1.7.0]
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getFallbackPointcutExpression( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization( [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    	at [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:

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

    <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="[email protected]@"/>
    	<property name="url" value="jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull"/>
    ... 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,


    P.S. Here is the 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.


    • #3
      The aspect in question looks like this:

      public class TestAspect {
      	@Pointcut(value="execution(* com.koutra.test.ITestAccess.*(..))")
      	public void performSomeTest() {}
      	public Object performTest(ProceedingJoinPoint pjp) throws Throwable {
      		Object retVal = pjp.proceed();
      		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:

      	<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 id="transactionManager"
      		<property name="dataSource" ref="dataSource"/>
      Hope this helps in pinpointing the problem...


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