2017-09-19 1 views
1

Lors du lancement avec mvn spring-boot: run ou même avec gradle renvoie ce problème.requis un bean de type 'org.springframework.security.core.userdetails.UserDetailsService' qui n'a pas pu être trouvé



*************************** 
APPLICATION FAILED TO START 
*************************** 

Description: 

Field userDetailsService in webroot.websrv.auth.config.WebSecurityConfiguration required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found. 


Action: 

Consider defining a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' in your configuration. 


BUILD SUCCESSFUL 

Total time: 19.013 secs 

Voici les principales classes, toutes les exigences me semble ok, je suis en utilisant le org.springframework.boot libérer 1.5.7.RELEASE


    package webroot.websrv.auth.config; 


    @Configuration 
    @EnableWebSecurity 
    @EnableGlobalMethodSecurity(prePostEnabled = true) 
    public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private JwtAuthenticationEntryPoint unauthorizedHandler; 

    @Autowired 
    private UserDetailsService userDetailsService; 

    @Autowired 
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { 
     authenticationManagerBuilder 
       .userDetailsService(userDetailsService) 
       .passwordEncoder(passwordEncoder()); 
    } 

    @Bean 
    public PasswordEncoder passwordEncoder() { 
     return new BCryptPasswordEncoder(); 
    } 

    @Bean 
    public JwtAuthenticationTokenFilter authenticationTokenFilterBean() throws Exception { 
     return new JwtAuthenticationTokenFilter(); 
    } 

    @Override 
    protected void configure(HttpSecurity httpSecurity) throws Exception { 
     httpSecurity 
       .csrf().disable() 

    .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() 
       .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() 
       .authorizeRequests() 
       .antMatchers(
         HttpMethod.GET, 
         "/", 
         "/**/*.html", 
         "/**/*.{png,jpg,jpeg,svg.ico}", 
         "/**/*.css", 
         "/**/*.js" 
       ).permitAll() 
       .antMatchers("/api/auth/**").permitAll() 
       .anyRequest().authenticated(); 

     httpSecurity 
       .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); 

     httpSecurity.headers().cacheControl(); 
    } 
    } 

et:


    package webroot.websrv;

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication 
public class WebcliApplication { 

public static void main(String[] args) { 
    SpringApplication.run(WebcliApplication.class, args); 
} 
} 

En utilisant maven ou gr Adle il renvoie le même problème. Tous les noms d'annotations et de paquets semblent être requis.

Merci! :)

Bruno

+0

Voir ma réponse et laissez-moi savoir que résoudre votre problème. –

+1

Vous pouvez également augmenter la réponse pour encourager. :) –

Répondre

2

Ajouter un haricot pour UserDetailsService

@Autowired 
private UserDetailsService userDetailsService; 

@Bean 
public UserDetailsService userDetailsService() { 
    return super.userDetailsService(); 
} 
0

Dans l'annotation classe make service

@Service

à

@Service ("userDetailsService")