Using @Inject Instance<blah> in Spring

一个人想着一个人 提交于 2019-12-10 18:49:29

问题


I know that Instance is not part of JSR 330, but is there a Spring equivalent? I'm interested in the fact that Instance implements Iterable, so Provider will not be the correct answer.

public interface Report { ... }

(there are 2 classes implementing Report with @Named annotations)

@Named
public class ReportRunner {
    @Inject private Instance<Report> reports;
}

results in: No qualifying bean of type [javax.enterprise.inject.Instance] found for dependency...


回答1:


Closing this question out because it has been answered in comments. As @JB Nizet mentioned above, List<Report> works.

For those that wonder what I was doing, it was a generic report runner, wherein each report has its own implementing class, each with a set of DB stored parameters. With this set up, I can leave the report runner running in my app server, drop in jars as necessary, hit re-scan on the sub-context that the ReportRunner maintains (which scans only the Reporting package) and I can modify reports on the fly, without a server restart.



来源:https://stackoverflow.com/questions/22875680/using-inject-instanceblah-in-spring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!