资源注入在查找作品时不适用于glassfish 4 [英] Recource injection doesn't work with glassfish 4 while lookup works
本文介绍了资源注入在查找作品时不适用于glassfish 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在glassfish 4的应用程序范围管理bean中使用资源注入,但glassfish无法正常工作,而是使用默认的derby数据库。有我的代码:
$ $ p $ code @Named(value =dbManager)
@ApplicationScoped
public class DbManager {
@Resource(name =jdbc / mydb)
private DataSource ds;
//但查找方法可行
ctx = new InitialContext();
ds =(DataSource)ctx.lookup(jdbc / mydb);
我找不到原因。
解决方案
试试这个
@Resource(mappedName =jdbc / mydb )
不是这个
@Resource(name =jdbc / mydb)
我在glassfish 4上:)
I use resource injection in my application scope managed bean with glassfish 4, but glassfish failed to work and using the default derby database instead. there is my code:
@Named(value = "dbManager")
@ApplicationScoped
public class DbManager {
@Resource(name = "jdbc/mydb")
private DataSource ds;
// but lookup method works
ctx = new InitialContext();
ds = (DataSource) ctx.lookup("jdbc/mydb");
I can't find the reason for this.
解决方案
try this
@Resource(mappedName = "jdbc/mydb")
instead of this
@Resource(name = "jdbc/mydb")
It works for me on glassfish 4. :)
这篇关于资源注入在查找作品时不适用于glassfish 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文