問題描述:使用嵌入式tomcat跑maven工程的mvc,一直報“No mapping found for HTTP request with URI”
解決方法:使用tomcat7:run-war 運行工程。 而不是tomcat7:run
原因解析:
@Configuration @EnableWebMvc @ComponentScan("com.wisely.highlight_springmvc4") public class MyMvcConfig { @Bean public InternalResourceViewResolver viewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setPrefix("/WEB-INF/classes/views/"); viewResolver.setSuffix(".jsp"); /* viewResolver.setSuffix(".html");*/ viewResolver.setViewClass(JstlView.class); return viewResolver; } }
https://tomcat.apache.org/maven-plugin-2.0-beta-1/tomcat7-maven-plugin/run-mojo.html
tomcat7:run
Full name:
org.apache.tomcat.maven:tomcat7-maven-plugin:2.0-beta-1:run
Description:
Attributes:
- Requires a Maven project to be executed.
- Requires dependency resolution of artifacts in scope: runtime.
- Since version: 2.0.
- Invokes the execution of the lifecycle phase compile prior to executing itself.
https://tomcat.apache.org/maven-plugin-2.0-beta-1/tomcat7-maven-plugin/run-war-mojo.html
tomcat7:run-war
Full name:
org.apache.tomcat.maven:tomcat7-maven-plugin:2.0-beta-1:run-war
Description:
Attributes:
- Requires a Maven project to be executed.
- Requires dependency resolution of artifacts in scope: runtime.
- Since version: 2.0.
- Invokes the execution of the lifecycle phase package prior to executing itself.