我寫的應用程序在啓動春季,春季安全與Thymeleaf,我試圖讓我的訪問靜態資源文件...春天引導安全性的靜態資源
這是我的項目結構...
3210我在模板/ index.html的HTML文件,其中我嘗試使用標籤
<img src="/praca.jpg" alt="sd"/>
爲什麼我總是得到404錯誤?我在哪裏做錯了什麼?
我一般初始化類:
@SpringBootApplication
public class Application extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(InzynierkaApplication.class, args);
}
}
我的安全類:
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private UserAuthenticationDetails userAuthenticationDetails;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userAuthenticationDetails);
auth.authenticationProvider(authenticationProvider());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setUserDetailsService(userAuthenticationDetails);
authenticationProvider.setPasswordEncoder(passwordEncoder());
return authenticationProvider;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/","/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/",true)
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutUrl("/logout")
.logoutSuccessUrl("/login?logout")
.invalidateHttpSession(true);
}
}
只需確認,整個頁面返回一個404或只是圖像資產? –
404只返回圖片資源。其他內容載入成功。 – technics