2014-03-28 4 views
1

스프링 부트 응용 프로그램에서 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 
) 

프로젝트 구조 :

 
MainProject 
    -- sub-project 
    src 
     main 
      resources 
      index.html 

Application 클래스 : 근본 원인을 찾을 수

@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.** 

답변

2

. 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; 
    } 
+1

내 대답을 삭제하고 당신을 업 그레 이드 –

관련 문제