Recource injection doesn't work with glassfish 4 while lookup works

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 07:26:07

问题


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.


回答1:


try this

 @Resource(mappedName = "jdbc/mydb")

instead of this

 @Resource(name = "jdbc/mydb")

It works for me on glassfish 4. :)



来源:https://stackoverflow.com/questions/17636198/recource-injection-doesnt-work-with-glassfish-4-while-lookup-works

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