dimanche 22 février 2015

Defining an alias with java @Configuration class

I'm trying to imitate the behavior of the Spring XML alias in @Configuration class.


I have an alias in XML that looks like that:



<alias name="${com.some.bean}" alias="myBean"/>


I have a @Configuration class that looks like that:



@Configuration
public class MyConfig {
@Lazy
@Bean(name = "bean1")
public MyBean bean1() { return new MyBean(); }

@Lazy
@Bean(name = "bean2")
public MyBean bean2() { return new MyBean(); }
}


I want to load dynamically either bean1 or bean2 an give the one that's loaded the alias myBean. according to the resolution of com.some.bean property. It's easy to do with XMLs, yet I can't find the @Configuation equivalent.


Note: I do not want to use profiles because that's not how my system currently works and changing all the property resolution to use profiles instead of property files is not an option at the moment.


Aucun commentaire:

Enregistrer un commentaire