gpt4 book ai didi

java - 获取 http://localhost:8080/resources/css/index.css net::ERR_ABORTED 404

转载 作者:太空宇宙 更新时间:2023-11-04 05:47:55 26 4
gpt4 key购买 nike

我知道关于这个主题也有类似的问题,但我似乎找不到解决方案。我有一个 Spring MVC 元素,问题是我在运行应用程序时收到浏览器日志中标题中指定的错误。如果我在浏览器中打开 index.html(不是从 Spring),CSS 就会被加载。

This is my structure.

index.html CSS 声明

    <link rel="stylesheet" type="text/css" th:href="@{ /css/index.css }"
href="../../resources/static/css/index.css">

Controller

@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();
}
}

一切正常。

关于java - 获取 http://localhost:8080/resources/css/index.css net::ERR_ABORTED 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58542650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com