Spring 3 ,with Java based configuration, and Resources access issue

Deadly 提交于 2019-12-01 05:47:59

You have defined wrong resourceLocation.

Instead of

registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");

you should have done

registry.addResourceHandler("/resources/**").addResourceLocations("/resources/**");

Because your css folder is inside resources folder you need to put the extra ** after the / only after that it will identify the css folder otherwise it will load only from the resources folders no subfolders will be considered.

Hope it helped you.

Cheers.

If you are using Spring Security, you might consider adding the webjars to the list of authorized requests by adding this line of code to your SecurityConfiguration Class:

@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http
  .authorizeRequests()
  .antMatchers("/resources/**", "/signup", "/about").permitAll()
  **.antMatchers("/webjars/**").permitAll()**
  .anyRequest().authenticated()
    .and()
 .formLogin().loginPage("/signin").permitAll()
    .and()
//...
 .logout().permitAll();
} 

If you are using Spring Security, you might consider adding the webjars to the list of authorized requests by adding this line of code to your SecurityConfiguration Class:

@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
   http
   .authorizeRequests()
   .antMatchers("/resources/**", "/signup", "/about").permitAll()
    **.antMatchers("/webjars/**").permitAll()**
    .anyRequest().authenticated()
    .and()
    .formLogin().loginPage("/signin").permitAll()
    .and()
    .logout().permitAll();
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!