Jsp 找不到带有URI的HTTP请求与注释配置Spring MVC和Jetty的映射
我使用的是仅注释配置,服务器启动,但当我访问某些页面时,错误显示: 警告:找不到URI为的HTTP请求的映射 名为的DispatcherServlet中的[/WEB-INF/view/main.jsp] 'org.springframework.web.servlet.DispatcherServlet-d7259e' 控制器映射工作正常,但没有加载JSP页面 我使用的是Jetty 9.2.0.M0和Spring MVC 4.0.4-RELEASE 码头配置:Jsp 找不到带有URI的HTTP请求与注释配置Spring MVC和Jetty的映射,jsp,spring-mvc,jetty-9,Jsp,Spring Mvc,Jetty 9,我使用的是仅注释配置,服务器启动,但当我访问某些页面时,错误显示: 警告:找不到URI为的HTTP请求的映射 名为的DispatcherServlet中的[/WEB-INF/view/main.jsp] 'org.springframework.web.servlet.DispatcherServlet-d7259e' 控制器映射工作正常,但没有加载JSP页面 我使用的是Jetty 9.2.0.M0和Spring MVC 4.0.4-RELEASE 码头配置: private static fi
private static final String CONTEXT_PATH = "/";
private static final String MAPPING_URL = "/*";
private void startServer(int port) throws Exception {
Server server = new Server(port);
server.addLifeCycleListener(new LifeCycleListener());
server.setHandler(getServletContextHandler(getContext()));
server.start();
server.join();
}
private static ServletContextHandler getServletContextHandler(WebApplicationContext context) throws IOException {
LOGGER.info("Preparing ServletContextHandler");
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath(CONTEXT_PATH);
contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
contextHandler.addEventListener(new ContextLoaderListener(context));
return contextHandler;
}
private static WebApplicationContext getContext() {
LOGGER.info("Preparing annotation context");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(SpringMVCConfig.class);
return context;
}
SpringMVCConfig:
@Configuration
@ComponentScan(basePackages = "my.package.controller")
@EnableWebMvc
public class SpringMVCConfig extends WebMvcConfigurerAdapter {
private static final Logger LOGGER = LogManager.getLogger(SpringMVCConfig.class);
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
LOGGER.info("Adding resource handlers");
registry.addResourceHandler("/i/**").addResourceLocations("classpath:WEB-INF/images/");
registry.addResourceHandler("/c/**").addResourceLocations("classpath:WEB-INF/css/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:WEB-INF/javascripts/");
}
@Bean
public ViewResolver prepareViewResolver() {
LOGGER.info("Returning view resolver");
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/view/");
resolver.setSuffix(".jsp");
// resolver.setViewClass(JstlView.class);
return resolver;
}
}
没有web.xml或任何其他xml文件
谢谢。在GitHub上使用此skelet,它是一个工作示例-