搜索和实践后,是这样的
同一个类中方法调用,不生效
@Service
public class A{
public String m1(){
return m2();
}
@Cacheable(cacheNames = "testCache")
public String m2(){
System.out.println("m2方法体");
return "m2结果";
}
}
不同类,才生效
@Service
public class A{
@Autowired
private B b;
public String m1(){
return b.m2();
}
}
@Service
public class B{
@Cacheable(cacheNames = "testCache")
public String m2(){
System.out.println("m2方法体");
return "m2结果";
}
}