0

注釈のみの構成を使用していますが、サーバーは起動しますが、ページにアクセスするとエラーが表示されます:

警告: 「org.springframework.web.servlet.DispatcherServlet-d7259e」という名前の DispatcherServlet で、URI [/WEB-INF/view/main.jsp] の HTTP 要求のマッピングが見つかりません

コントローラ マッピングは正常に機能しますが、JSP ページが読み込まれません。

Jetty 9.2.0.M0 と Spring MVC 4.0.4-RELEASE を使用しています。

桟橋の設定:

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 ファイルもありません。

main.jsp が存在する

ありがとう。

4

1 に答える 1

0

GitHub でこのスケルトを使用してください。これは実用的な例です - https://github.com/jasonish/jetty-springmvc-thymeleaf-template

于 2014-05-08T11:27:29.340 に答える