0
votes

I'm using annotation only configuration, server starts but when I access some page, error is shown:

WARNING: No mapping found for HTTP request with URI [/WEB-INF/view/main.jsp] in DispatcherServlet with name 'org.springframework.web.servlet.DispatcherServlet-d7259e'

Controller mapping works okay but no JSP page is loaded.

I'm using Jetty 9.2.0.M0 and Spring MVC 4.0.4-RELEASE.

Jetty config:

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;
    }

}

There is no web.xml nor any other xml files.

main.jsp exists

Thanks.

1

1 Answers

0
votes

Use this skelet on GitHub, it's a working example - https://github.com/jasonish/jetty-springmvc-thymeleaf-template