Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring security实现Thymeleaf中静态资源的可视性_Java_Spring Boot_Spring Security_Thymeleaf - Fatal编程技术网

Java 使用Spring security实现Thymeleaf中静态资源的可视性

Java 使用Spring security实现Thymeleaf中静态资源的可视性,java,spring-boot,spring-security,thymeleaf,Java,Spring Boot,Spring Security,Thymeleaf,我有如下目录层次结构: -resources | |-static | |-css | |-js |-templates |-error |-fragments 这幅图: @Override protected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity .csrf() .disa

我有如下目录层次结构:

-resources
|
|-static
|  |-css
|  |-js
|-templates
   |-error
   |-fragments
这幅图:

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                .csrf()
                .disable()
                .authorizeRequests()
                .antMatchers("/login").not().fullyAuthenticated()
                .antMatchers("/admin/**").hasRole("ADMIN")
                .antMatchers("/main").hasRole("USER")
                .antMatchers("/resources/**", "/registration").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .defaultSuccessUrl("/main")
                .permitAll()
                .and()
                .logout()
                .permitAll()
                .logoutSuccessUrl("/login");
    }
我需要一些帮助:1)我的静态资源在授权之前不可见 2) 授权后重定向到css或js文件


请帮帮我。我做错了什么?

你应该在你的资源文件夹中创建一个公共文件夹,Spring将向所有人提供放置在
/css/**
/js/**
/images/**
文件夹中的文件,这些文件没有经过身份验证

如果您将img.jpg像那样放在images文件夹中,
src/main/resources/public/images/img.jpg
可以在http://localhost:8080/images/img.jpg试试这个:

private static final String[] PUBLIC_MATCHERS = {
        "/css/**",
        "/js/**",
        "/images/**",
};
//...
    http
        .authorizeRequests().
        antMatchers(PUBLIC_MATCHERS).
        permitAll().anyRequest().authenticated();
//...
不客气。:)几个月前,我还是SpringBoot和Thymeleaf的初学者,我很高兴我能帮助别人。