정적 리소스 위치에 대한 스프링 부트 레지스터 src/main/resources/static
, src/main/resources/public
, src/main/resources/resources
등을 참조하십시오. 스프링 부트 웹 정적 리소스
src/main/resources
-static
-js
-stomp.js
을 얻었고, HTML에서 (템플릿 폴더에 위치) :
<script type="text/javascript" th:src="@{/js/stomp.js}"></script>
하지만 스크립트 (GET http://localhost:8080/js/stomp.js 404 (Not Found)
)에 대한 (404)를 얻었다. 내가 뭘 잘못 했니?
<script type="text/javascript" src="../static/js/stomp.js"></script>
및
<script type="text/javascript" src="/js/stomp.js"></script>
을 시도했다.
내 MVC 구성 (하나의 뷰 - 컨트롤러) :
@EnableWebMvc
@ComponentScan(basePackages = {"controller"})
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/sock").setViewName("/index");
}
}
와 나는 POM에
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
을 얻었다. @EnableWebMvc
의
http://stackoverflow.com/questions/17312034/cant-find-css-images-and-js-static-files-in-spring – Thunda