dimanche 6 mai 2018

Create proxy for a interface, which could inject by @Autowired, proxy invokes different implement by key parameter

I want to define a annotation like @PlatformRelated, once it is marked in a interface, there will be a proxy bean at spring context, and this proxy bean should be @Priority.I want this proxy could invoke different implement according to key parameter @KeyPrameter.And I still wanna use sprint features like @Async,@Trasaction,etc... at my Implement1 and Implement2.

@PlatformRelated
interface MyInterface {
   method(@KeyPrameter String parameter);
}

@Component
class Implement1 implements MyInterface {
   method(String parameter){
       //do something 111
   }
}

@Component
class Implement2 implements MyInterface {
   method(String parameter){
       //do something  222
   }
}

@Service
class BusinessService{
    @Autowired
    private MyInterface myInterface;

    public void doSomething() {
        myInterface.method("key1");
        //Implement1 work
        myInterface.method("key2");
        //Implement2 work
    }
}

Do you guys have some good idea to complete it?





Aucun commentaire:

Enregistrer un commentaire