简体   繁体   中英

Spring boot security, oauth2 and thymeleaf static resource cannot be found

I have added my css and js under Resource then static folder. When I access path "forgotpassword" all my static resource are loaded correctly. enter image description here

However when I try to access the same path but this time with a trailing slash "forgotpassword/" all my static resource are not loaded. I get status 404 not found enter image description here

Here is my security configuration

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(-20)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    @Qualifier("customUserDetailsService")
    UserDetailsService userDetailsService;

    static private Logger logger = LoggerFactory.getLogger(Oauth2AuthserverApplication.class);

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .userDetailsService(userDetailsService)
                .passwordEncoder(passwordEncoder());
    }

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http
                .authorizeRequests()
                .antMatchers("/resources/**", "/forgotpassword/**")
                .permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .requestMatchers().antMatchers("/forgotpassword/**", "/login", "/oauth/authorize", "/oauth/confirm_access");
        // @formatter:on
    }

}

对于css,这是我必须做的th:href="@{/css/Default/css/style.css}"和js th:src="@{/js/jquery/dist/jquery.min.js}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM