我正在用XML配置实现Springcache,并希望摆脱所有的注释。我只想替换应用程序Context.xml文件中的注释。这是我的代码 -
//DummyBean.java
package com.spring.example;
interface DummyBean {
public String getCity();
}
//DummyBeanImpl.java
package 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.java
package 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();
}
}
12345678_0001
相关分类