简体   繁体   English

带有spring cache和aspectj的NoClassDefFoundError

[英]NoClassDefFoundError with spring cache and aspectj

I am getting this error in my spring webapp (spring 3.1), and I don't know why. 我在春季webapp(春季3.1)中收到此错误,我不知道为什么。

org.springframework.web.util.NestedServletException: Handler processing failed; org.springframework.web.util.NestedServletException:处理程序处理失败; nested exception is java.lang.NoClassDefFoundError: mypackage/TestCache$AjcClosure1 嵌套异常是java.lang.NoClassDefFoundError:mypackage / TestCache $ AjcClosure1

(the $AjcClosure1 is weird) $AjcClosure1很奇怪)

If I comment the annotation @Cacheable in the class below the error is gone. 如果我在下面的类中注释注释@Cacheable ,则错误消失了。

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) 我尝试了代理和aspectj模式(在代理模式下减少错误但缓存无效)

This web application was built initially with roo and use spring mvc and webflow. 这个Web应用程序最初是使用roo构建的,并使用spring mvc和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). 所以applicationContext.xml或webmvc-config.xml中有相当多的xml(我无法理解一些bean在做什么)。 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) 我使用m2e-wtp在eclipse中运行wepapps,而pom.xml正在使用插件aspectj-maven-plugin(但不知道它做了什么)

It looks like the issue is related with aspectj, but I never used aspectJ. 看起来问题与aspectj有关,但我从未使用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! 如果有人spring / java / aspectj guru可以解释我是什么造成了这个错误以及我如何使我的缓存工作它会很棒! (I could find only tutorial but no sample project using the cacheable annotation). (我只能找到教程但没有使用可缓存注释的示例项目)。

似乎问题来自于所有类$ AjcClosure [n] .class都没有发布的事实,唯一的方法是删除,webapps,干净启动并重新发布webapp。

One problem (may not the one that causes the NoClassDefFoundError) is that you can use Spring Functions like @Cacheable only for Spring Beans. 一个问题(可能不是导致NoClassDefFoundError的问题)是你可以像@Cacheable一样使用Spring函数,例如@Cacheable 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. 因此,如果您通过new创建一个类(并且这个类没有@Configurable注释)那么这是一个普通的类而不是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. - 这可能会导致AspectJ模式中的这个stange错误,但我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM