2017-09-28 3 views
0

Je suis incapable de comprendre pourquoi la source de données JDBC JNDI échoueConfiguration JNDI JDBC pour le Web App dans Tomcat

context.xml dans META-INF

<?xml version="1.0" encoding="UTF-8"?> 
<Context reloadable="true"> 
    <Resource auth="Container" 
     name="jdbc/BigByte" 
     type="javax.sql.DataSource" 
     driverClassName="com.ibm.as400.access.AS400JDBCDriver" 
     url="jdbc:as400://****.****/****;prompt=false;sort=language;sort language=ENU;sort weight=shared" 
     username="****" 
     password="****" 
     maxIdle="10" 
     maxActive="200" 
     maxWait="5" 
     removeAbandoned="true" 
     removeAbandonedTimeout="1200" /> 
</Context> 

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
    * 
    * 
    * 
    <resource-ref> 
     <description>Big Byte DB Connection</description> 
     <res-ref-name>jdbc/BigByte</res-ref-name> 
     <res-type>javax.sql.DataSource</res-type> 
     <res-auth>Container</res-auth> 
     <res-sharing-scope>Shareable</res-sharing-scope> 
    </resource-ref> 
</web-app> 

mon test

DataSource ds = null; 
    try { 
     Context initCtx = new InitialContext(); 
     NamingEnumeration<NameClassPair> list = initCtx.list(""); 
     while (list.hasMore()) { 
      System.out.println(list.next().getName()); 
     } 
     Context envCtx = (Context)initCtx.lookup("java:comp/env"); 
     ds = (DataSource)envCtx.lookup("jdbc/BigByte"); 
     Connection con = ds.getConnection(); 
     PreparedStatement ps = con.prepareStatement(
       "select * from XAAQREV1 where AQABVN = ?"); 
     ps.setString(1, "*****"); 
     ResultSet rs = ps.executeQuery(); 
     while (rs.next()) { 
      String uid = rs.getString("AQABVN"); 
      System.out.println(uid); 
     } 
    } catch (NamingException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } catch (SQLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

mon sortie console

2017-09-28 10:13:26,482/: [http-nio-8080-exec-10/:ERROR] - Cannot find the class org/apache/naming/LocalStrings.class 
2017-09-28 10:13:26,619/: [http-nio-8080-exec-10/:ERROR] - Cannot find the class org/apache/naming/LocalStrings_en.class 
2017-09-28 10:13:26,775/: [http-nio-8080-exec-10/:ERROR] - Cannot find the class org/apache/naming/LocalStrings_en_US.class 
2017-09-28 10:13:28,091/: [http-nio-8080-exec-10/:ERROR] - Cannot find the class org/apache/juli/JdkLoggerConfig.class 
javax.naming.NameNotFoundException: Name [java:comp/env] is not bound in this Context. Unable to find [java:comp]. 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:824) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:172) 
    at javax.naming.InitialContext.lookup(Unknown Source) 
    at webx0001.XAC3DFR_ObFnc.ObRun(XAC3DFR_ObFnc.java:189) 
    ... 

Lorsque j'effectue un test, la liste NamingEnumeration ne contient aucun élément.

Quels sont les messages de la console concernant les classes manquantes?

Qu'est-ce qui me manque?

Répondre

0

Je ne manquais de rien. Mon projet utilise un ClassLoader personnalisé qui casse Tomcat JNDI. J'ai vérifié cela avec une simple servlet dans un projet simple.