since the Redis cache is updated, each service implements the update function in the basic Rediscacheupdate interface, and in the scheduled task, it uses the List<rediscacheupdate The > method calls update in bulk, but there are cache dependencies between the service, such as service B relying on service A's cache, so that if B is updated then it will not fetch the cached data and every time it is taken in the database, it is a waste of time, so you need to control a, B In the list is injected in the order, then the question comes, how to control their call order?
Spring has long provided us with a solution that can proactively change the injection order of each implementation class by annotating the order, and the spring version here is 4.0.8-release.
test It, sure enough, in the given order to inject, the very aspect.
Interface base{
void print ();
}
@Component
@Order (3)
class A implements base{
void print () {
syso ("A");
}
}
@Component
@Order (2)
class B implements base{
void print () {
syso ("B");
}
}
@Component
@Order (1)
class C implements base{
void print () {
syso ("C");
}
}
@Component
class invokerclass{
@Autowired
list<base> List;
void print () {
For (Base base:list) {
base.print ();
}
}
}
Public class main{
Public static void Main (string[] args) {
ApplicationContext context = new Classpathxmlapplicationcontext ("Classpath*:spring.xml");
Invokerclass in = Context.getbean (Invokerclass.class);
in.print ();
}
Printed results: CBA This is mainly the use of @order annotations, the annotation assignment value according to the size of the value of the priority of the call, the greater the lower the priority. This completely alters the order in which the beans are called. can control their sequencing.
Spring controls the order in which implementation classes that implement the same interface are called in the list