开发者

Glassfish - Resource Injection not working

开发者 https://www.devze.com 2023-01-25 01:14 出处:网络
Using NetBeans IDE and Glassfish Server. For some reason I can\'t get a DataSource injected (have tried a million variations).

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.j开发者_Python百科ava: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?


Choose the option "name" by "lookup" -->

@Resource(lookup = "java:global/env/jdbc/__default")
DataSource dataSource;


Make sure you're in a session bean or injection won't work.

Here's an example of how I inject

@Resource(name="jdbc/my_db") private DataSource dataSource;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号