저는 새로운 스프링 부트 및 스프링 프레임 워크입니다. 내게 따르면, 웹 응용 프로그램은 스프링 부트로 작성하고 배포하기가 쉽지만 샘플 스프링 웹 응용 프로그램을 실행하면 응용 프로그램에 "welcome.html"페이지가 없습니다. 나는 stackoverflow에 대한 모든 비슷한 질문을 확인하고 나를 일하지 못했습니다. 나는 작은 문제를 볼 수 없지만 내 문제를 찾지 못했습니다. 내 응용 프로그램 구조 및 코드는 다음과 같습니다 :스프링 부트에 매핑이 없습니다.
하여 MyApplication 클래스는 다음과 같습니다 :
@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
WelcomeController 클래스는 다음과 같습니다 :
@Controller
public class WelcomeController {
@RequestMapping(value = "/welcome")
public String welcome() {
return "welcome"; //<- this is your login.html if it is directly in resource/templates folder
}
}
application.properties 파일은 다음과 같습니다 :
spring.mvc.view.prefix = templates/
spring.mvc.view.suffix = .html
spring.mvc.static-path-pattern=/resources/**
WebMvcAppConfig 클래스는 다음과 같습니다 : 대한
public class WebMvcAppConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
super.addViewControllers(registry); //To change body of generated methods, choose Tools | Templates.
registry.addViewController("/welcome").setViewName("welcome.html");
}
}
스프링 부트 응용 프로그램에서'@ EnableWebMvc'을 원하지 않을 것입니다. 또한'@ SpringBootApplication'은 이미 패키지가 사용 된 패키지에 대한 컴포넌트 스캐닝을 가능하게합니다.이 경우에는'net.samplespringboot'가 사용됩니다. –
@forever_software HTML 페이지가 정적 인 경우 기본 응용 프로그램 클래스 이외에 공유 한 내용이 필요하지 않습니다. 정적 파일을'src/main/resource/static'에 넣는 것만으로 스프링 부트가 자동 설정하는 정적 리소스 지원에 의해 자동으로 서비스됩니다. –
기본 패키지에없는 src/main/resources에서 application.properties를 이동하십시오. –