springboot没有启动静态web内容



我试图在我的春季启动应用程序中启动index.html,但请参阅404。我缺少什么依赖?

build.gradle(多项目(

project('sub-project')
{
apply plugin: 'spring-boot'
compile (
    "org.springframework.boot:spring-boot-starter-web:1.0.0.RC5",
    "org.springframework.boot:spring-boot-starter-actuator:1.0.0.RC5"
.. few more app specific dependencies
)

项目结构:

主要项目--子项目src主要的资源index.html

应用类别:

@Configuration
@EnableAutoConfiguration
class Application {
    public static void main(String[] args) {
        SpringApplication.run([SpringServlet, Application, "classpath:/META-INF/com/my/package/bootstrap.xml"] as Object[], args)
    }
}
**Launching http://localhost:8080/index.html throws 404.**

找到根本原因。将SpringServlet的Url映射更改为"Rest"资源特定路径修复了它。早期的"/*"也被SpringServlet解释,无法呈现index.html。

class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run([Application, "classpath:/META-INF/com/my/package/mgmt/bootstrap.xml"] as Object[], args)
    }
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application);
    }
    @Bean
    ServletRegistrationBean jerseyServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new SpringServlet(), "/rest/*");
        Map<String, String> params = ["com.sun.jersey.config.property.packages": "com.my.package.mgmt.impl;com.wordnik.swagger.jersey.listing"]
        registration.setInitParameters(params)
        return registration;
    }
    @Bean
    ServletRegistrationBean jerseyJaxrsConfig() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new DefaultJaxrsConfig(), "/api/*");
        Map<String, String> params = ["swagger.api.basepath": "http://localhost:8080/api", "api.version": "0.1.0"]
        registration.setInitParameters(params)
        return registration;
    }
@Configuration
public class WebConfig implements WebMvcConfigurer {
/** do not interpret .123 extension as a lotus spreadsheet */
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) 
    {
        configurer.favorPathExtension(false);
    }
/**
  ./resources/public is not working without this
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**")
            .addResourceLocations("classpath:/public/");
}

}

最新更新