5

I am getting this error in my spring webapp (spring 3.1), and I don't know why.

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: mypackage/TestCache$AjcClosure1

(the $AjcClosure1 is weird)

If I comment the annotation @Cacheable in the class below the error is gone.

public class TestCache {

        @Cacheable(value ="myCache")
        public List<String> getDummyList(){
            Logger l = Logger.getLogger(this.getClass());
            l.error("calling getDummyList");
            ArrayList<String> foo = new ArrayList<String>();
            foo.add("foo");
            foo.add("bar");
            return foo;
        }

    }

My controller class (simplified):

@Controller
@RequestMapping("/mypage")
public class MyController {


    @RequestMapping
    public String index(ModelMap model, Locale locale) {
        TestCache tc = new TestCache();
        ...
    }
}

Application Context (only cache part):

<cache:annotation-driven mode="aspectj"/>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/>
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml"/>

I tried proxy and aspectj mode (in proxy mode less error but the cache was doing nothing)

This web application was built initially with roo and use spring mvc and webflow. So there is quite a lot of xml in the applicationContext.xml or webmvc-config.xml (and I am not able to understand what some beans are doing). I am running the wepapps in eclipse with m2e-wtp and the pom.xml is using the plug-in aspectj-maven-plugin (but no idea what it does)

It looks like the issue is related with aspectj, but I never used aspectJ. If anyone spring/java/aspectj guru can explain me what is making this error and how I can make my cache working it would be awesome! (I could find only tutorial but no sample project using the cacheable annotation).

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
jpprade
  • 3,497
  • 3
  • 45
  • 58
  • Refresh the target folder, see http://stackoverflow.com/questions/16283268/how-to-deploy-generated-resources-to-tomcat-with-m2e-wtp – xmedeko Dec 17 '14 at 08:39

2 Answers2

3

It seems that the problem comes from the fact that all the class$AjcClosure[n].class aren't published and the only way to do it is remove, the webapps, clean start and republish the webapp.

jpprade
  • 3,497
  • 3
  • 45
  • 58
0

One problem (may not the one that causes the NoClassDefFoundError) is that you can use Spring Functions like @Cacheable only for Spring Beans. So if you create an class via new (and this class it not annotated by @Configurable) then this is a normal class and not a Spring bean. Therefore the annotation is ignored in proxy mode. -- May this will also result in this stange error in AspectJ mode, but I don't know.

Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Thanks this is helping me a little, I start to understand better how thing works! but I created an interface and declare a bean in the application context, and autowire it in the controller with the same error. I will look at the @configurable tag – jpprade Mar 15 '12 at 21:46
  • 1
    Ok I think I found the problem come from eclipse or wtp pluggin, If I Check the target path under eclipse there is a compiled myclass$AjcClosure1 but if I look in tomcat this file is not published – jpprade Mar 17 '12 at 18:23