2
我需要配置AJP連接器嵌入的Tomcat https://tomcat.apache.org/tomcat-8.0-doc/config/ajp.html 等於以下配置:如何在嵌入式tomcat中配置AJP連接器?
<Connector port="8009" protocol="AJP/1.3" redirectPort="8080" />
怎麼辦呢?
我需要配置AJP連接器嵌入的Tomcat https://tomcat.apache.org/tomcat-8.0-doc/config/ajp.html 等於以下配置:如何在嵌入式tomcat中配置AJP連接器?
<Connector port="8009" protocol="AJP/1.3" redirectPort="8080" />
怎麼辦呢?
// initialize tomcat with default nio connector
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getHost().setAppBase(".");
tomcat.addWebapp("/", ".");
// create an AJP connector
Connector ajpConnector = new Connector("AJP/1.3");
ajpConnector.setPort(8009);
ajpConnector.setRedirectPort(8080);
ajpConnector.setSecure(false);
// add connector to tomcat
tomcat.getService().addConnector(ajpConnector);
tomcat.start();
tomcat.getServer().await();
從啓動日誌:
Dec 26, 2016 10:45:26 AM org.apache.catalina.core.StandardContext setPath
WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
Dec 26, 2016 10:45:27 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Dec 26, 2016 10:45:27 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 26, 2016 10:45:27 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Dec 26, 2016 10:45:27 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Dec 26, 2016 10:45:27 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Dec 26, 2016 10:45:27 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.28
Dec 26, 2016 10:45:27 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Dec 26, 2016 10:45:28 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Dec 26, 2016 10:45:28 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Dec 26, 2016 10:45:28 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
http-nio
正在端口8080和ajp-nio
監聽8009端口