Glassfish - 资源注入不起作用
使用 NetBeans IDE 和 Glassfish 服务器。由于某种原因,我无法注入数据源(已经尝试了一百万种变体)。
private DataSource iserver;
@Resource(name="jdbc/iserver", type=DataSource.class)
public void setIServer(DataSource dataSource) {
this.iserver = dataSource;
}
(我已经尝试将 @Resource 注释直接添加到该字段)。连接池和jdbc资源在Glassfish上配置,暂时我添加了解决方法代码(在同一个类中):
ctx = new InitialContext();
iserver = (DataSource) ctx.lookup("jdbc/iserver");
解决方法代码工作完美。我在 Glassfish 日志中没有看到任何明显相关错误。我确实看到了这一点,但不确定它是否相关:
*name can not be null at javax.management.ObjectName.construct(ObjectName.java:405) * at javax.management.ObjectName.(ObjectName.java :1403)在org.glassfish.admingui.common.handlers.ProxyHandlers.getRuntimeProxyAttrs(ProxyHandlers.java:289)在org.glassfish.admingui.common.handlers.ProxyHandlers.getProxyAttrs(ProxyHandlers.java:273)在...
任何建议?
Using NetBeans IDE and Glassfish Server. For some reason I can't get a DataSource injected (have tried a million variations).
private DataSource iserver;
@Resource(name="jdbc/iserver", type=DataSource.class)
public void setIServer(DataSource dataSource) {
this.iserver = dataSource;
}
(I already tried adding @Resource annotation directly to the field). The connection pool and jdbc resource are configured on Glassfish, and for the time being, I have added the workaround code (in the same class):
ctx = new InitialContext();
iserver = (DataSource) ctx.lookup("jdbc/iserver");
The workaround code works perfectly. I don't see any obvious relevant errors in Glassfish log. I do see this, but not sure it's related:
*name cannot be null at javax.management.ObjectName.construct(ObjectName.java:405) * at javax.management.ObjectName.(ObjectName.java:1403) at org.glassfish.admingui.common.handlers.ProxyHandlers.getRuntimeProxyAttrs(ProxyHandlers.java:289) at org.glassfish.admingui.common.handlers.ProxyHandlers.getProxyAttrs(ProxyHandlers.java:273) at ...
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过
"lookup"
选择选项"name"
-->
Choose the option
"name"
by"lookup"
-->
确保您处于会话 bean 中,否则注入将不起作用。
这是我如何注入的示例
Make sure you're in a session bean or injection won't work.
Here's an example of how I inject