第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Springcache 不僅適用於 XML 配置

Springcache 不僅適用於 XML 配置

胡子哥哥 2022-09-01 19:34:54
我正在用XML配置實現(xiàn)Springcache,并希望擺脫所有的注釋。我只想替換應(yīng)用程序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條經(jīng)驗 獲得超5個贊

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

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

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

另請參閱參考指南


查看完整回答
反對 回復(fù) 2022-09-01
  • 1 回答
  • 0 關(guān)注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號