Java 得到http://localhost:8080/resources/css/index.css net::ERR_中止404

Java 得到http://localhost:8080/resources/css/index.css net::ERR_中止404,java,html,css,spring-mvc,http-status-code-404,Java,Html,Css,Spring Mvc,Http Status Code 404,我知道在这个问题上也有类似的问题,但我似乎找不到解决办法。我有一个SpringMVC项目,问题是我在运行应用程序时在浏览器日志的标题中指定了错误。如果我在browse(不是从Spring)中打开index.html,就会加载CSS index.html CSS声明 <link rel="stylesheet" type="text/css" th:href="@{ /css/index.css }" href="../../resources/static/c

我知道在这个问题上也有类似的问题,但我似乎找不到解决办法。我有一个SpringMVC项目,问题是我在运行应用程序时在浏览器日志的标题中指定了错误。如果我在browse(不是从Spring)中打开index.html,就会加载CSS

index.html CSS声明

    <link rel="stylesheet" type="text/css" th:href="@{ /css/index.css }"
          href="../../resources/static/css/index.css">
@Override
public void configure(WebSecurity web) throws Exception {
    super.configure(web);

    web.ignoring().antMatchers("/resources/**", "/static/**", "/css/**", "/icons/**", "/javascript/**");

}
我甚至尝试将此添加到安全配置中

    <link rel="stylesheet" type="text/css" th:href="@{ /css/index.css }"
          href="../../resources/static/css/index.css">
@Override
public void configure(WebSecurity web) throws Exception {
    super.configure(web);

    web.ignoring().antMatchers("/resources/**", "/static/**", "/css/**", "/icons/**", "/javascript/**");

}
但它不起作用

路径很好,因为正如我在浏览器中打开index.html时所说,CSS已加载,我认为问题在于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();
}
}

一切都很好。

从我搜索的内容来看,大写字母在以这种方式访问它们时很重要,也许在浏览器中不重要,你能确认这是否可能吗?@BugsForBreakfast不是这样,仍然会出错这是怎么回事?从我的搜索中,你需要一个“静态”目录,所以你有权限访问它,这是最准确的@BugsForBreakfast感谢所有的研究,最后,我发现了问题并发布了答案。