java - GET http://localhost:8080/resources/css/index.css net::ERR_ABORTED 404
问题描述
我知道关于这个主题有类似的问题,但我似乎无法找到解决方案。我有一个 Spring MVC 项目,问题是我在运行应用程序时收到浏览器日志中标题中指定的错误。如果我在浏览器(不是来自 Spring)中打开 index.html,则会加载 CSS。
index.html CSS 声明
<link rel="stylesheet" type="text/css" th:href="@{ /css/index.css }"
href="../../resources/static/css/index.css">
控制器
@RequestMapping(value = { "/", "/index"}, method = RequestMethod.GET)
public ModelAndView index() {
ModelAndView model = new ModelAndView();
model.setViewName("index");
return model;
}
我什至尝试在SecurityConfiguration中添加它
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers("/resources/**", "/static/**", "/css/**", "/icons/**", "/javascript/**");
}
但它不起作用。
路径很好,因为正如我所说,当我在浏览器中打开index.html时加载了 CSS,我认为问题出在SecurityConfiguration类上,但我不知道它是什么。
有人有什么主意吗?
解决方案
所以错误确实来自SecurityConfiguration因为我没有使用正确的注释。正确的是
@EnableWebSecurity
我正在使用
@EnableWebMvc
所以现在我的课看起来像这样:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/", "/index").permitAll().and()
.exceptionHandling().accessDeniedPage("/libraryAppError");
http.authorizeRequests().antMatchers("/resources/**").permitAll().anyRequest().permitAll();
}
}
一切正常。
推荐阅读
- python - 将箱线图的平均值绘制为箱线图
- typescript - 如何在 Typescript 中增加枚举?
- vue.js - vue.js 应用程序中的动态路由
- css - 我的外部容器如何正确对齐所有内部元素?
- c# - Azure Functions RunOnStartUp 在配置中而不是在编译时设置?
- python - CircleCI 上 Ubuntu 映像的文件权限
- excel - VBA脚本或其他东西自动按下按钮
- javascript - 溢出属性似乎不适用于导航链接的动画
- node.js - 出现错误:02016002:系统库:stat:共享主机计划上没有这样的文件或目录
- pthreads - 当变量被 2 个线程共享并受 pthread_mutex_lock 保护时,一个线程优先处理一个变量