1
我已經添加我的css和js資源下然後靜態文件夾。當我訪問路徑「忘記密碼」時,我的所有靜態資源都正確加載。 enter image description here春季開機安全,oauth2和thymeleaf靜態資源無法找到
但是,當我嘗試訪問相同的路徑,但這次用尾部斜線「忘記密碼/」我的所有靜態資源都沒有加載。我得到的狀態未找到404 enter image description here
這裏是我的安全配置
@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
}
}
看來問題是位於您的模板。你不應該使用相對路徑(js/my.js)加載你的靜態文件,而是使用絕對路徑:(/js/my.js)我希望它可以幫助 – Tony
謝謝。它的工作,對於CSS這是我必須做的:href =「@ {/ css/Default/css/style.css}」和js th:src =「@ {/ js/jquery/dist/jquery .min.js}」 –