亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Springcache 不僅適用於 XML 配置

Springcache 不僅適用於 XML 配置

胡子哥哥 2022-09-01 19:34:54
我正在用XML配置實現Springcache,并希望擺脫所有的注釋。我只想替換應用程序Context.xml文件中的注釋。這是我的代碼 -//DummyBean.javapackage com.spring.example;interface DummyBean {    public String getCity();}//DummyBeanImpl.javapackage com.spring.example;import org.springframework.cache.annotation.CacheConfig;import org.springframework.cache.annotation.Cacheable;import org.springframework.cache.annotation.EnableCaching;@EnableCaching@CacheConfig(cacheNames={"myCache"})public class DummyBeanImpl implements DummyBean {    private String city = "New York";    @Cacheable()    public String getCity() {        System.out.println("DummyBean.getCity() called!");        return city;    }}SpringAwareAnnotationXMLConfig.javapackage com.spring.example;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.support.AbstractApplicationContext;import org.springframework.context.support.GenericXmlApplicationContext;public class SpringAwareAnnotationXMLConfig {  public static void main(String[] args) throws Exception {    AbstractApplicationContext context = new GenericXmlApplicationContext("applicationContext.xml");    DummyBean personService = (DummyBean) context.getBean("myBean");    System.out.println(personService.getCity());    System.out.println(personService.getCity());    System.out.println(personService.getCity());    ((AbstractApplicationContext) context).close();  }}
查看完整描述

1 回答

?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

使用 XML 配置的各個方面時,您還需要添加一個部分來應用該方面。aop:config

<aop:config>
    <aop:advisor advice-ref="cacheAdvice" pointcut="execution(* com.spring.example.DummyBean+.*(..))"/>
</aop:config>

假設是一個由此實現的接口,應該可以解決問題。這表示您要將(方面)應用于與表達式匹配的 Bean。DummyBeancom.spring.example.DummyBeanImplcacheAdvice

另請參閱參考指南


查看完整回答
反對 回復 2022-09-01
  • 1 回答
  • 0 關注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號