現在、私はannotitonsで新しいオブジェクトを作成したいときにCDIに大きな問題があります。CDI JavaEE 7の@Configurableに相当する
私はすべてのクラスを '@Connector'でテジャートしました。その後、私はクラスごとに新しいオブジェクトを作成します。これは正常に動作しますが、 '@Inject'を介して注入しようとするオブジェクトにServiceHandlerを注入したいと考えています。 ここでの問題は、CDIがこれらのオブジェクトを認識せず、それらを挿入できないことです。現在、私はこの問題を解決するための回避策を持っていますが、これは本当にかわいいものではありません。私はCDIの初心者です。私はSpringの@Configurableアノテーションと同等のものを探しています。
private Set<ApiDao> determineApiDaos() {
Set<Class<?>> classes = new Reflections("###packageName###").getTypesAnnotatedWith(Connector.class);
return FluentIterable.from(classes)
.transform(CLASS_TO_API_DAO_FUNCTION)
.filter(Predicates.notNull())
.toSet();
}
private ApiDao instantiateApiDao(Class apiDao) {
try {
ApiDao newApiDao = (ApiDao) apiDao.newInstance();
newApiDao.setConfigurationService(configurationService); // Workaround inject service during creation
return newApiDao;
} catch (Exception e) {
LOG.error("Could not initialize Connector.", e);
return null;
}
}
もう少し説明できますか?なぜCDIはこれらのクラスについて知りませんか? –