Regeneration injection does not work with glassfish 4 when searching

I am using resource injection in my bean-driven application area using glass fish 4, but glass fish does not work and instead uses the default derby database. there is my code:

@Named(value = "dbManager") @ApplicationScoped public class DbManager { @Resource(name = "jdbc/mydb") private DataSource ds; 

// but the search method works

  ctx = new InitialContext(); ds = (DataSource) ctx.lookup("jdbc/mydb"); 

I can not find the reason for this.

+4
source share
1 answer

try it

  @Resource(mappedName = "jdbc/mydb") 

instead of this

  @Resource(name = "jdbc/mydb") 

It works for me on glassfish 4. :)

+5
source

Source: https://habr.com/ru/post/1491300/


All Articles