我正在学习弹簧引导和弹簧安全与angularjs。未能在Spring Boot项目上获取资源/ static/bower_components/angular/angular.js?
以前我用CDN在我的html中加载角度,一切都很好。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-messages.js"></script>
但很多人使用bower
比较好,所以我想试一试说。 我已经安装了bower,将目录设置为resources/static/bower_components
,安装依赖项并更改脚本。
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-messages/angular-messages.js"></script>
,但是,当我加载HTML,它说失败404当我试图在网络上,Whitelabel Error Page
出错。
据我所知,resources/static
中的所有内容都将公开发布?为什么我无法访问它?
- 编辑 -
我从Not loading static Resources in Spring boot, Thymeleaf and AngularJs app想一个解决方案,但还是失败了。
@Configuration
public class WebConfig extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/bower_components/**")
.addResourceLocations(classpath:"/static/bower_components/");
}
}
什么是目录是什么呢?它是'src/main/resources/static'还是仅仅是与你的项目根有关的'resources/static'? –
是的,它是'src \ main \ resources \ static \ bower_components' –