将jboss迁移到tomcat-javax.naming.NamingException

问题描述 投票:0回答:1

我们正在将Struts 1.2项目从JDK 1.6迁移到1.8,并将应用程序服务器jboss5.1迁移到tomcat 8.0。数据库连接工作正常,初始页面正在加载和填充一些数据。但是,当我执行任何操作(“提交”按钮)时,它会引发异常javax.naming.NamingException: Cannot create resource instance相同的代码在jboss 5.1中运行,但在Tomcat 8中出现错误。

但是我怀疑该错误的原因是UserTransaction需要在context.xml中单独定义,但不确定。请告诉我。

UserTransaction ut = (UserTransaction) myCntxt.lookup("java:comp/UserTransaction");

如果需要定义UserTransaction,请让我知道如何在Tomcat服务器中进行配置?

在META-INF / context.xml下的context.xml中添加了数据库配置

<Resource name="jdbc/Test1" 
   auth="Container" 
   type="javax.sql.DataSource" 
   maxTotal="100" 
   maxIdle="30" 
   maxWaitMillis="10000" 
   username="xxxxx" 
   password="xxxxx" 
   driverClassName="oracle.jdbc.OracleDriver" 
   url="jdbc:oracle:thin:@xxxx:1527:xxxx" />

<Resource name="jdbc/Test2" 
   auth="Container" 
   type="javax.sql.DataSource" 
   maxTotal="100" 
   maxIdle="30" 
   maxWaitMillis="10000" 
   username="xxxxx" 
   password="xxxxx" 
   driverClassName="oracle.jdbc.OracleDriver" 
   url="jdbc:oracle:thin:@xxxx:1527:xxxx" />

在{project} /WEB-INF/web.xml下的web.xml中添加了数据源引用

<resource-ref>
   <description>Oracle Datasource</description>
   <res-ref-name>jdbc/Test1</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

<resource-ref>
   <description>Oracle Datasource</description>
   <res-ref-name>jdbc/Test2</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

样本代码

public static void dbInit(String test1dataSourceReference,String test2dataSourceReference) throws Exception
    {

        Context ctx = new InitialContext();
            tds =(DataSource) ctx.lookup("java:comp/env/" + test1dataSourceReference);
            cds = (DataSource) ctx.lookup("java:comp/env/" + test2dataSourceReference);

    }

Stack-trace:

Dec 25, 2019 7:28:07 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
Dec 25, 2019 7:28:07 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
Dec 25, 2019 7:28:07 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
Dec 25, 2019 7:28:07 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
Dec 25, 2019 7:28:08 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.logic.LocalStrings', returnNull=true
Dec 25, 2019 7:28:08 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
Dec 25, 2019 7:28:08 AM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
Dec 25, 2019 7:28:22 AM org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class javax.naming.NamingException
Dec 25, 2019 7:28:22 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [action] in context with path [/policy] threw exception [javax.naming.NamingException: Cannot create resource instance] with root cause
javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:96)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:847)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:158)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:835)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:172)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at com.db.DbQuery.saveAppRejValue(DbQuery.java:798)
    at com.actions.PolicyAction.executeDisplay(PolicyAction.java:298)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

我们正在将Struts 1.2项目从JDK 1.6迁移到1.8,并将应用程序服务器jboss5.1迁移到tomcat 8.0。数据库连接工作正常,初始页面正在加载和填充一些数据。但是...

java tomcat java-ee jndi jta
1个回答
0
投票

由于TomEE Comparison page指示Tomcat不支持JTA(JSR 907):

© www.soinside.com 2019 - 2024. All rights reserved.