使用内置tomcat启动idea创建的项目失败了
Topic sourceAppConfig 启动类
Tomcat tomcat = new Tomcat();tomcat.setPort(Integer.getInteger("port", 8080));tomcat.getConnector();Context ctx = tomcat.addWebapp("", new File("web").getAbsolutePath());WebResourceRoot resources = new StandardRoot(ctx);resources.addPreResources( new DirResourceSet(resources, "/WEB-INF/classes", new File("target/classes").getAbsolutePath(), "/"));ctx.setResources(resources);tomcat.start(); //Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]] at (AppConfig.java:46)tomcat.getServer().await();
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextClass</param-name> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> </init-param> <init-param> <param-name>contextConfigLocation</param-name> <param-value>com.itranswarp.learnjava.AppConfig</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping></web-app>
再次调整格式
AppConfig 启动类
Tomcat tomcat = new Tomcat();
tomcat.setPort(Integer.getInteger("port", 8080));
tomcat.getConnector();
Context ctx = tomcat.addWebapp("", new File("web").getAbsolutePath());
WebResourceRoot resources = new StandardRoot(ctx);resources.addPreResources(
new DirResourceSet(resources, "/WEB-INF/classes", new File("target/classes").getAbsolutePath(), "/"));
ctx.setResources(resources);tomcat.start(); //Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]] at (AppConfig.java:46)
tomcat.getServer().await();
- 1
用户5273497715
bug项目地址:https://github.com/MakeItAlright/mvc_app/tree/master
AppConfig 启动类
错误信息
项目tree
web.xml
完整错误信息