javascript - Spring Boot Static Resources -
i trying create spring boot mvc , angularjs. modified view resolver of app can point application on "web-inf/pages/" folder static html files. on html file declared source of angularjs libraries using webjars dependency
<script src="webjars/angularjs/1.5.5/angular.min.js"></script>
i know in order make work have declare classpath of webjars libray on application's resourcehandlerregistry on configuration file added line of code
@override public void addresourcehandlers(resourcehandlerregistry registry) { registry.addresourcehandler("/webjars/**").addresourcelocations("classpath:/meta-inf/resources/webjars/"); }
after adding line code somehow works makes me curious line on html file
<script src="resources/js/angular/app.js"></script>
i noticed on spring mvc application in order spring detect javascript files under webapp's resource folder have declare folder on resourcehandlerregistry
this
public void addresourcehandlers(resourcehandlerregistry registry) { registry.addresourcehandler("/resources/**").addresourcelocations("/resources/"); }
but haven't declared webapp's resource folder on spring boot's resourcehandlerregistry
but still application can see app.js file , angularjs codes still works. here file structure of application
src |--main |--java |--resources |--webapp |--resources |--js |--angular |--app.js |--web-inf |--index.html
that's how spring boot web's static works. default, should put js,image,css in resources/static. if using thymeleaf, put template in resources. sample below.
this how call, note ../.. goes /resources :
<!doctype html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" href="../../css/bootstrap.min.css" /> <link rel="stylesheet" th:href="@{/css/signin.css}" href="../../css/signin.css" /> </head>
update after op gave file structure : resources located @ webapp/resources default static folder spring mvc ( not spring boot - refer this blog ).
the spring boot's static folders located @ (refer spring io blog ) :
- /meta_inf/resources
- /static
- /resources
- /public