3

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.

  • post yur faces-config and web.xml – Andy Jul 14 '13 at 04:40
  • 3
    Andy, I read [Trouble injecting resources](http://stackoverflow.com/questions/6422577/trouble-injecting-resources-with-java-ee-6-and-glassfish-3-1-using-resource). and replace @Resource(name = "jdbc/mydb") with @Resource(lookup = "jdbc/mydb") and it works now. – user2449972 Jul 17 '13 at 03:10

1 Answers1

4

try this

 @Resource(mappedName = "jdbc/mydb")

instead of this

 @Resource(name = "jdbc/mydb")

It works for me on glassfish 4. :)

user1300356
  • 41
  • 1
  • 3