如何使spring服务于静态html文件?

时间:2015-09-11 06:11:52

标签: java spring spring-mvc

我创建了没有web.xml的Spring应用程序。我想从WEB-INF提供静态index.html。以下是来源:

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {return new Class<?>[]{AppConfiguration.class};}

    @Override
    protected Class<?>[] getServletConfigClasses() {return new Class[]{WebConfiguration.class};}

    @Override
    protected String[] getServletMappings() {return new String[]{"/ololo/*"};}
}

import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfiguration {}


@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/index.html").addResourceLocations("classpath:/WEB-INF/view/index.html");
    }
}

一切似乎都是正确的 - index.html放在webapp\WEB-INF\view\index.html中,但我仍然在日志中(contextRoot是我部署的战争的上下文根):

[2015-09-11T11:06:21.247+0500] [glassfish 4.1] [WARNING] [] [org.springframework.web.servlet.PageNotFound] [tid: _ThreadID=29 _ThreadName=http-listener-1(3)] [timeMillis: 1441951581247] [levelValue: 900] [[
  No mapping found for HTTP request with URI [/contextRoot/ololo/index.html] in DispatcherServlet with name 'dispatcher']]

配置有什么问题?

已更新

当出现问题时,Spring中的路径是一个大问题,所以欢迎在调度请求或我可以看到配置实例化的上下文中有关spring调试的任何建议。

0 个答案:

没有答案