我有一个 jar,它在带有 Java 8.0.66 的独立 tomcat 8.0.28 服务器中部署和运行
我希望从嵌入式 Tomcat 运行它来运行集成测试。战争部署但未能开始,我没有想法,我收到以下错误:
Dec 07, 2015 6:11:46 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-9191"]
Dec 07, 2015 6:11:46 PM org.apache.tomcat.util.net.NioSelectorPool
getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 07, 2015 6:11:46 PM org.apache.catalina.core.StandardService
startInternal
INFO: Starting service Tomcat
Dec 07, 2015 6:11:46 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.28
Dec 07, 2015 5:43:47 PM org.apache.catalina.startup.ContextConfig
getDefaultWebXmlFragment
INFO: No global web.xml found
Dec 07, 2015 5:43:47 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException:
org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Tomcat].StandardHost[localhost].
StandardContext[/StrateboBackEnd]]
...
Caused by: org.apache.catalina.LifecycleException:
Failed to start component StandardEngine[Tomcat].StandardHost[localhost].
StandardContext[/myApp]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.NoSuchMethodError:
javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
我有以下嵌入 tomcat 的设置
final Tomcat tomcat = new Tomcat();
tomcat.setPort(9191);
File baseDir = new File(".");
Context context = tomcat.addContext("", baseDir.getAbsolutePath());
tomcat.addWebapp("/Myapp", "C://Users//Add//git//Myapp//build//libs//Myapp-1.1.war");
tomcat.enableNaming();
ContextResource res = new ContextResource();
res.setName("jdbc/myDatabase");
res.setType("javax.sql.DataSource");
res.setAuth("Container");
res.setProperty("username", "username");
res.setProperty("password", "password");
res.setProperty("driverClassName","net.sourceforge.jtds.jdbc.Driver");
res.setProperty("url", "jdbc:jtds:sqlserver://127.0.0.1:1433//myDatabase");
res.setProperty("maxTotal", "10");
res.setProperty("maxIdle", "10");
res.setProperty("maxWaitMillis", "10000");
res.setProperty("removeAbandonedTimeout","300");
res.setProperty("defaultAutoCommit","true");
context.getNamingResources().addResource(res);
tomcat.start();
tomcat.getServer().await();
我有一个用于正常部署的 context.xml ,但这并没有从我所知道的嵌入中读取。
由于罐子可以独立运行,我知道罐子不是问题
有这个信息行 INFO: No global web.xml found 这可能指向一个问题但找不到参考以防万一这是我的 gradle 文件的相关部分的依赖项
compile 'org.apache.tomcat:tomcat-util:8.0.28'
compile 'org.apache.tomcat.embed:tomcat-embed-core:8.0.28'
compile 'org.apache.tomcat.embed:tomcat-embed-jasper:8.0.28'
compile 'org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.28'
compile 'org.apache.tomcat:tomcat-dbcp:8.0.28'
任何建议非常感谢?另外一点,有没有办法让tomcat就它不喜欢的东西提供更好的反馈?