Ich baue einen kleinen Jersey (1.9) REST-Service und habe eine Java-Klasse als Sub-Ressource, wo ich eine Verbindung zur lokalen Datenbank (Postgres 9.3).Name ist nicht in diesem Kontext gebunden ... Datenquelle nicht gefunden
Für die Datenquelle ich bereits die Einträge in context.xml hinzufügen haben:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/userProfile">
<Resource
auth="Container"
driverClassName="org.postgresql.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/apiUserProfile"
password="postgres"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/apiUserProfile"
username="postgres"/>
</Context>
Wenn ich die Anwendung ausführen und rufen Sie die folgende Ressource:
http://localhost:8084/userProfile/rest/user/conn
die Seite ist leer - kein Inhalt - und der Tomcat (8.0) auf Netbeans (8.1) wirft Fehler: Nullzeiger Ausnahme
javax.naming.NameNotFoundException: Name [jdbc/apiUserProfile] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at net.rest.dao.DbConn.apiUserProfileConn(DbConn.java:23)
at net.rest.service.userProfile.returnDatabaseStatus(userProfile.java:51)
Ich habe auch schon die JAR-Dateien in den librairies:
lib/mysql-connector-java-5.1.39-bin.jar
lib/postgresql-9.3-1100-jdbc4.jar
und hier ist die Unterressourcenklasse für die Datenquelle Verbindung:
package net.rest.dao;
import javax.naming.*;
import javax.sql.*;
public class DbConn {
private static DataSource DbConn = null;
private static Context context = null;
public static DataSource apiUserProfileConn() throws Exception {
if(DbConn != null){
return DbConn;
}
try {
if(context == null){
context = new InitialContext();
}
DbConn = (DataSource) context.lookup("jdbc/apiUserProfile");
}
catch (Exception e) {
e.printStackTrace();
}
return DbConn;
}
}
Jede Idee, pls. wie dies zu beheben ..
Vielen Dank
a.kasbi