2

I have following method;

    @Cacheable(value = "psgSiteToMap", key = "'P2M_'.concat(#siteName)")
    public Map getSiteDetail(String siteName) {
        Map map = new HashMap();
        .....
        //construct map variable here
        .......
        return map;
    }

While project startup, cannot autowire class this method belongs to. If i change above method as following;

    @Cacheable(value = "psgSiteToMap", key = "'P2M_'.concat(#siteName)")
    private Map getSiteDetail(String siteName) {
        Map map = new HashMap();
        .....
        //construct map variable here
        ................
        return map;
    }

    public Map getSiteDetailPublic(String siteName) {
         return this.getSiteDetail(siteName);
    }

it works. Is there any restriction on @Cacheable annotation for public methods?

Thanks in advance

4

1 回答 1

4

默认情况下,Spring AOP 仅适用于公共方法。您需要 AspectJ 和加载时间或编译时间编织以使其适用于私有方法。

所以它适用于你的情况意味着当你移动@Cacheableprivate方法时,代理根本不会被创建,它的工作原理是自动装配,但不是缓存。

您可能没有proxy-target-class在 XML 配置中设置属性或其等效的注释属性。您能否添加您正在使用的 Spring 配置和类定义行。我对它是否实现任何接口感兴趣?我会用更多细节来扩展我的答案。

于 2013-08-12T16:12:53.840 回答