Dans CDI, comment configurer mes beans?CDI: Comment prendre soin de la configuration des haricots?
Disons que j'ai ce code:
class JawaBotApp {
private void init(String configFilePathString) throws JawaBotException {
ConfigBean cb = new JaxbConfigPersister(configFilePathString).load();
JawaBotApp.jawaBot = JawaBot.create(cb);
}
}
class JawaBot {
public static JawaBot create(ConfigBean cb) throws JawaBotException{
JawaBot bot = new JawaBot();
bot.applyConfig(cb);
bot.init();
return bot;
}
}
Comment pourrais-je le convertir afin que les deux pourraient être des haricots CDI?
Je pensais à annoter le create()
avec @Produces
, mais qui aurait besoin d'avoir non-statique, et le réécrire de sorte que le ConfigBean obtient injecté, qui aurait besoin de réécrire JaxbConfigPersister
ou créer un objet wrapper ... Trop de travail pour rien. Y a-t-il une meilleure approche?
Sonne bien, va essayer. –