EJB3.1属性文件注入
有没有一些简单的方法可以将加载有文件的 Properties 类从类路径注入到 EJB (3.1) 中?
像这样的:
@Resource(name="filename.properties", loader=some.properties.loader)
private Properties someProperties;
谢谢你,
Bozo
is there some simple way to inject Properties class loaded with a file from the classpath into EJB (3.1)?
Something like this:
@Resource(name="filename.properties", loader=some.properties.loader)
private Properties someProperties;
Thank you,
Bozo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 bkail 所说,您可以通过以下方式实现这一目标。我不确定您的 loader=some.properties.loader 的真正含义,因此跳过了执行任何操作,但提供了选项,以防您想使用 loader.getClass( ).getResourceAsStream("filename.properties");
首先定义您的注入类型
,然后为其创建一个生产者
,然后将其注入到您的命名组件中。
我这样做是为了查看焊接文档,其中以 @HttpParam 为例此处。这是根据焊接1.1.0,在焊接1.0.0中,获取注释可以这样完成
As bkail said, you can achieve this in the following way. I am not sure what your
loader=some.properties.loader
really meant, so skipped doing anything with that, but provided option for that in case you want to load using theloader.getClass().getResourceAsStream ("filename.properties");
First define your injection type
Then create a producer for that
Then inject it into your Named component.
I did this looking into the weld documentation where the @HttpParam is given as an example here. This is as per weld 1.1.0, in weld 1.0.0, the getting annotation can be done like this
如果您使用的应用程序服务器将 WELD 作为 CDI 实现(例如 Glassfish 3.x 或 JBoss 7.x 或 Weblogic 12),那么您需要使用 WELD 扩展,这在 WELD 中进行了解释文档 此处
就像将其添加到 POM 中一样简单
If the application server you are using has WELD as the CDI implementation (Glassfish 3.x or JBoss 7.x or Weblogic 12 are examples) then you want to use a WELD extension which is explained in the WELD documentation here
It is as simple as adding this to your POM