2017-10-16 5 views
0

私は次のspringMVCウェブアプリケーションを持っています。これがディレクトリです。これは私のセキュリティ設定がSpringMVCのロットリソースファイル(JSとCSS)

enter image description here

です:私はベンダーフォルダ内のすべてのCSSやJSを持っています。私は、 "/ベンダー/ "/リソース/ベンダー/ " を追加しようとしている" が、何も動いていないようにみえ:

SecurityConfiguration

@Configuration 
@EnableWebSecurity 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private BCryptPasswordEncoder bCryptPasswordEncoder; 

    @Autowired 
    private DataSource dataSource; 

    @Value("${spring.queries.users-query}") 
    private String usersQuery; 

    @Value("${spring.queries.roles-query}") 
    private String rolesQuery; 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) 
      throws Exception { 
     auth. 
       jdbcAuthentication() 
       .usersByUsernameQuery(usersQuery) 
       .authoritiesByUsernameQuery(rolesQuery) 
       .dataSource(dataSource) 
       .passwordEncoder(bCryptPasswordEncoder); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http. 
       authorizeRequests() 
       .antMatchers("/", "/resources/vendor/**", "/vendor/**", "/css/**").permitAll() 
       .antMatchers("/login").permitAll() 
       .antMatchers("/registration").permitAll() 
       .antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest() 
       .authenticated().and().csrf().disable().formLogin() 
       .loginPage("/login").failureUrl("/login?error=true") 
       .defaultSuccessUrl("/admin/home") 
       .usernameParameter("email") 
       .passwordParameter("password") 
       .and().logout() 
       .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
       .logoutSuccessUrl("/").and().exceptionHandling() 
       .accessDeniedPage("/access-denied"); 
    } 

    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web 
       .ignoring() 
       .antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**", "/vendor/**","/favicon.ico"); 
    } 

} 

とのWebConfigを。リソースパスが設定されている:

WebMvcConfig

@Configuration 
public class WebMvcConfig extends WebMvcConfigurerAdapter { 

    /** 
    * @return 
    */ 
    @Bean 
    public BCryptPasswordEncoder passwordEncoder() { 
     BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); 
     return bCryptPasswordEncoder; 
    } 

    @Override 
    public void addResourceHandlers(final ResourceHandlerRegistry registry) { 
     registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); 
    } 

} 

リソースがロードされていません。 404エラーいいえ:

enter image description here

これは働いて、同じファイルの例です。

enter image description here

HTMLヘッダー:

<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 
    <title>TEST</title> 

    <!-- Bootstrap core CSS--> 
    <link href="vendor/bootstrap/css/bootstrap.min.css" > 
    <!-- Custom fonts for this template--> 
    <link href="vendor/font-awesome/css/font-awesome.min.css" type="text/css"> 
    <!-- Custom styles for this template--> 
    <link href="css/sb-admin.css" > 

</head> 

答えて

1

あなたは、CSSやJSを配置する必要があります\src\main\resources\staticの内部にあるので、ベンダフォルダを使用する場合は、staticフォールド内に移動する必要がありますr。