I don't understand the aims of the Class/Type level resource annotation.
Why to declare a Class/Type level resource annotation :
Code: Select all
@Resource(name="jdbc/mydatabase", type=javax.sql.DataSource.class, mappedName="java:/DefaultDS" )
@Stateless
public class GeneralEJB3Knowledge implements GeneralEJB3KnowledgeRemote {
@Resource(name="jdbc/mydatabase") javax.sql.DataSource datasource;
public String testResourceRef() {
String result = "Connection has been retrieved !!";
try {
datasource.getConnection().close();
} catch (Exception e) {
e.printStackTrace();
result = "Exception caught: " + e.getClass().getName();
}
return result;
}
}
Code: Select all
@Stateless
public class GeneralEJB3Knowledge implements GeneralEJB3KnowledgeRemote {
@Resource(name="jdbc/mydatabase", mappedName="java:/DefaultDS" ) javax.sql.DataSource datasource;
public String testResourceRef() {
String result = "Connection has been retrieved !!";
try {
datasource.getConnection().close();
} catch (Exception e) {
e.printStackTrace();
result = "Exception caught: " + e.getClass().getName();
}
return result;
}
}
Thank you by advance for your help.