我试图通过禁用自动配置来在spring boot应用程序中提供静态内容,如下所示。
@Configuration
@ComponentScan(basePackages = { "com.lashes.studio" })
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
/* other codes */
@Override
public void addResourceHandlers(final ResourceHandlerRegistry
registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/", "/resources/");
}
/* other codes */
}
和我的安全配置类允许/ resources / **即
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/","/login*","/login*", "/logout*", "/signin/**",
"/signup/**", "/customLogin",
"/user/registration*", "/registrationConfirm*",
"/expiredAccount*", "/registration*",
"/badUser*", "/user/resendRegistrationToken*" ,
"/forgetPassword*", "/user/resetPassword*",
"/user/changePassword*", "/emailError*", "/resources/**",
"/old/user/registration*","/successRegister*")
.permitAll()
.antMatchers("/invalidSession").anonymous()
.antMatchers("/user/updatePassword*","/user/savePassword*",
"/updatePassword*").hasAuthority("CHANGE_PASSWORD_PRIVILEGE")
.anyRequest().hasAnyAuthority("READ_PRIVILEGE")
.and()
.formLogin()
.loginPage("/admin")
.defaultSuccessUrl("/homepage.html")
.failureUrl("/login?error=true")
.successHandler(myAuthenticationSuccessHandler)
.failureHandler(authenticationFailureHandler)
.permitAll()
.and()
.sessionManagement()
.invalidSessionUrl("/invalidSession.html")
.maximumSessions(1).sessionRegistry(sessionRegistry()).and()
.sessionFixation().none()
.and()
.logout()
.logoutSuccessHandler(myLogoutSuccessHandler)
.invalidateHttpSession(false)
.logoutSuccessUrl("/logout.html?logSucc=true")
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.rememberMe().rememberMeServices(rememberMeServices()).key("theKey");
}
现在,我希望通过这样的浏览器访问静态内容:-
http://localhost:8080/resources/static/css/jquery.fancybox.css
但是我得到404 not found错误。