Hey I'm testing a dataSource configuration on Liberty 22.0.0.12 with a servlet and facing the problem that the "@Resorce" annotation is not finding the dataSoure while looking up the dataSource via the initialContext works.
This is my dataSource definition in liberty (with feature `
jakartaee-9.1` loaded:
<dataSource id="db2DB" jndiName="jdbc/db2DS" jdbcDriverRef="db2XADriver" containerAuthDataRef="db2AuthData" statementCacheSize="10" connectionManagerRef="db2CM" recoveryAuthDataRef="db2AuthData" type="javax.sql.XADataSource" >
<properties databaseName="HHUE" serverName="localhost" portNumber="60000" driverType="4" />
</dataSource>
Using the dataSource definition above the following code returns null for `ds1' (but dies not use the authData (which is afaik working as designed)):
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Resource(lookup = "jdbc/db2DS")
DataSource ds1;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Statement stmt = null;
Connection con = null;
try {
// ds1 = (DataSource) new InitialContext().lookup("jdbc/db2DS");
However the following code returns a dataSource object for `ds1`:
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
// @Resource(lookup = "jdbc/db2DS")
DataSource ds1;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Statement stmt = null;
Connection con = null;
try {
ds1 = (DataSource) new InitialContext().lookup("jdbc/db2DS");
Any help ob why the "@Resource" annotation does not work abd getting it working is much appreciated. Thanks!
------------------------------
Hermann Huebler
2innovate IT Consulting GmbH
Vienna
Austria
#IBMChampion
------------------------------