问题
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