1 回答
TA贡献1836条经验 获得超13个赞
明白了..只需要启用命名即可。
tomcat.enableNaming();
在我的主要空白处:
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("temp");
tomcat.setPort(8080);
tomcat.enableNaming();
tomcat.getConnector(); // Tomcat 9 we need to get the connector. it not by default.
String contextPath = "/Test";
String warFilePath = "D:\\Test\\embedded\\Test.war";
tomcat.getHost().setAppBase(".");
StandardContext ctx = (StandardContext) tomcat.addWebapp(contextPath, warFilePath);
((StandardJarScanner) ctx.getJarScanner()).setScanAllDirectories(true);
((StandardJarScanner) ctx.getJarScanner()).setScanAllFiles(true);
((StandardJarScanner) ctx.getJarScanner()).setScanClassPath(true);
tomcat.start();
tomcat.getServer().await();
添加回答
举报