2016-07-14 6 views
0

Ich kämpfe mit einigen Konfigurationen, die meine statischen Ressourcen (js, css usw.) im Frühjahr Anwendung nicht mehr verfügbar sind. Kann ein Körper darauf hinweisen, was ich vermisse? Hier ist der Code. Beachten Sie, dass sich JS und CSS in folgenden Ordnern befinden. Beachten Sie auch, dass vor dem Frühjahr Sicherheit ermöglicht diese Ressourcen zugänglichStatische Ressourcen sind nicht mehr verfügbar, nachdem die Federsicherheit aktiviert ist

Web Pages -> 
    WEB-INF -> 
      resources -> 
       and here 2 folders js and css 

in meine JSP Seite i jquery in js Ordner mit folgendem Link

<script src="resources/js/jquery.js"></script> 

und der Fehler im Browser

zugreifen möchten Fehler beim Laden der Ressource: http://localhost:8010/resources/js/js.js Der Server hat mit dem Status 404 (Nicht gefunden) geantwortet.

@Configuration 
@EnableScheduling  // if you want certain function running on the backend on recurrning basis like very 5 second a function call itself then you have to ensbale this. this will enable all classes defined as Service and Scheduled to be running on backend automatically. see example in com.outbottle.controllers.ScheduledTasks.java 
@ComponentScan("com.outbottle, com.JavaAnatatedClass") //this will import all beans marked as @Controller, or @Repository, or @Service, or @Component in the application context 
@ImportResource({"classpath:beans1.xml"}) //this will import all beans in the application context from this xml file 
@EnableWebMvc 
public class Config extends WebMvcConfigurerAdapter { 

    @Bean 
    public UrlBasedViewResolver setupViewResolver() { 
      ..... 
      ..... 
    } 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 

     registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/**"); 

    }  

Hier ist die Sicherheitskonfigurationsdatei.

@Configuration 
@EnableWebSecurity 
//@PropertySource("classpath:jdbc.properties") 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 


    @Autowired 
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { 

     AuthenticationService as = new AuthenticationService();  
     auth.userDetailsService(as); 
    } 


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

     http.authorizeRequests() 
     .antMatchers("/", "/home", "/REST").permitAll() 
     .antMatchers("/resources/**").permitAll() 
     .antMatchers("/admin/**").access("hasAuthority('ADMIN')") //you have to use hasAuthority because in AuthenticationService you are using GrantedAuthority object. i replaced hasRole with hasAuthority.  check the detailes below in comments 
     .antMatchers("/db/**").access("hasAuthority('ADMIN') and hasAuthority('DBA')") 

     //Custom Login Form with fields and values 
     //.and().formLogin()  //this will show default spring login page 
     .and().formLogin().loginPage("/login") 
     .usernameParameter("ssoId").passwordParameter("password") //these aret the fields on the login page for user and password 
     .and().csrf()    
     .and().exceptionHandling().accessDeniedPage("/Access_Denied"); 

    } 

Antwort

0

ich einige Hit tat und versuchen, und fand das funktioniert

registry.addResourceHandler("/resources/js/*").addResourceLocations("/WEB-INF/resources/js/"); 
registry.addResourceHandler("/resources/css/*").addResourceLocations("/WEB-INF/resources/css/"); 

aus irgendwelchen Gründen/WEB-INF/resources/js/* oder ** nicht funktioniert

Auch bin ich einzeln Hinzufügen jedes Verzeichnisses zu Ressourcen.

Shahzad

+0

Normalerweise sollte ein Browser nichts von/WEB-INF bekommen können. Es kann jedoch explizit von Handlern geliefert werden. Ich würde sie sofort in das Webapp-Verzeichnis stellen/like/resources/js. –