将Apache Tomcat嵌入Eclipse Web应用程序项目。
当我使用最新的Tomcat 8(8.0.5 Embedded)JAR作为依赖项时,代码能正常运行,该服务器响应地址为http://localhost:8080,但是当使用最新版本的Tomcat 9(9.0.5 Embedded)JAR时,它无法以同样的方式启动,也无法在此地址响应。
代码非常简单。我已经尽可能彻底地研究了,但没有找出问题所在。
当我使用最新的Tomcat 8(8.0.5 Embedded)JAR作为依赖项时,代码能正常运行,该服务器响应地址为http://localhost:8080,但是当使用最新版本的Tomcat 9(9.0.5 Embedded)JAR时,它无法以同样的方式启动,也无法在此地址响应。
代码非常简单。我已经尽可能彻底地研究了,但没有找出问题所在。
package app;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class Main {
public static void main(String[] args) {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
try {
tomcat.start();
} catch (LifecycleException e) {
e.printStackTrace();
}
tomcat.getServer().await();
}
}
使用Tomcat 9.0.5嵌入式jar时的控制台输出:
org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
使用Tomcat 8.0.5嵌入式jar时的控制台输出:
org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]