Hook before @Autowire (constructor and variable)?

58 Views Asked by At

Is there any possibility to execute some code before every autowiring (for method and variable autowiring)? Because under some circumstances I want to add a primary component before this autowire/injection happened.

I have different services implementing the same interface (business implementation, rest client, ...). Now it depends on several circumstances which implementation should be used. Because of this I implemented a proxy service (annotated with @Primary) which is created dynamically. At the moment at this is done at "BeanDefinitionRegistryPostProcessor" - but I need to scan for all components and this take some time.

I want to avoid this and want to create this proxy dynamically - I tried to add the proxy at "postProcessBeforeInitialization". But there is a problem if a bean should be injected which is not already created - because there are more than one possible instance and none of them is @Primary (because without initialization of this component my proxy is missing at this moment of autowiring).

0

There are 0 best solutions below