Java JNDI连接在Tomcat上工作,但不';我不能在Websphere上工作
我在数据库中使用JNDI连接与SQL Server连接,直到今天,我始终使用tomcat应用程序服务器在本地计算机上运行我的应用程序: Context.xml 在我的tomcat中一切正常,但现在我正在迁移到WebSphere8.5服务器。出于某种原因,它在websphere中不起作用,我想知道websphere中是否有额外的步骤。我得到了以下错误: 日志 GERECIADORDOEXAO中的第30行为:Java JNDI连接在Tomcat上工作,但不';我不能在Websphere上工作,java,sql-server,tomcat,websphere,jndi,Java,Sql Server,Tomcat,Websphere,Jndi,我在数据库中使用JNDI连接与SQL Server连接,直到今天,我始终使用tomcat应用程序服务器在本地计算机上运行我的应用程序: Context.xml 在我的tomcat中一切正常,但现在我正在迁移到WebSphere8.5服务器。出于某种原因,它在websphere中不起作用,我想知道websphere中是否有额外的步骤。我得到了以下错误: 日志 GERECIADORDOEXAO中的第30行为: dataSource = (DataSource) ctx.lookup("java:/c
dataSource = (DataSource) ctx.lookup("java:/comp/env/jdbc/dataquality_sqlServer");
Websphere:
尝试查找java:comp/env/jdbc/dataquality\u sqlServer(而不是java:/comp/env)尝试查找java:comp/env/jdbc/dataquality\u sqlServer(而不是java:/comp/env)
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/dataquality_sqlServer</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
public void startDB() {
Context envContext = null;
DataSource dataSource = null;
try {
Context ctx = new InitialContext();
dataSource = (DataSource) ctx.lookup("java:/comp/env/jdbc/dataquality_sqlServer");
System.out.println("conectado com sucesso!JNDI");
conexao = dataSource.getConnection();
conexao.setAutoCommit(false);
} catch (Exception e){
e.printStackTrace();
//return null;
}finally {
if(envContext != null){
try{
envContext.close();
} catch (NamingException e){
System.out.println();
e.printStackTrace();
}
}
}
}
[10/22/18 9:50:10:469 BRST] 000001c0 SystemErr R javax.naming.NameNotFoundException: Name not found in context "java:".
[10/22/18 9:50:10:469 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1970)
[10/22/18 9:50:10:469 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1377)
[10/22/18 9:50:10:470 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1220)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1142)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at javax.naming.InitialContext.lookup(InitialContext.java:428)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr R at DAO.GerenciadorDeConexao.iniciar(GerenciadorDeConexao.java:30)
dataSource = (DataSource) ctx.lookup("java:/comp/env/jdbc/dataquality_sqlServer");