TomEE is a great project, combining the lightweight experience of Tomcat with Java EE features. I have many JDBC datasources declared in context.xml, but when I want to use that Datasource via JNDI I get an Exception. So how can I get working a JDBC datasource declared in context.xml in TomEE
My datasource declared in context.xml
<Resource auth="Container"
name="local_jdbc_db"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb"
username="user"
password="pass" />
The code to get the Datasource from JNDI
Context contextoInicial = new InitialContext();
Context contexto = (Context) contextoInicial.lookup("java:comp/env");
DataSource ds= (DataSource) contexto.lookup("local_jdbc_db");
context.xml
is placed inMETA-INF
folder. – Porridgecontext.xml
in the webapp'sMETA-INF/
folder fixed it. I was placing it in a different folder (maven generated) which issrc/main/resources/META-INF
. The correct location would besrc/main/webapp/META-INF
. – Connett