2017-09-19 1 views
1

mvn spring-boot를 사용하여 시작할 때 : 실행하거나 심지어 gradle을 반환합니다.찾을 수없는 'org.springframework.security.core.userdetails.UserDetailsService'유형의 bean이 필요합니다.


    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); 
} 
} 
: 여기


*************************** 
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 

메인 클래스이다, 모든 요구 사항은, 내가 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(); 
    } 
    } 

및 해제 org.springframework.boot 사용하고 나에게 좋아 보인다 받는다는 또는 GR을 사용하여

그것은 똑같은 문제를 되 돌린다. 모든 주석과 패키지 이름은 필요한 것처럼 보입니다.

감사합니다. :)

브루노

+0

제 대답을보고 문제 해결에 대해 알려주십시오. –

+1

격려를 위해 응답을 upvote 할 수도 있습니다. :) –

답변

2

서비스 수준의 메이크업 주석에서 UserDetailsService

@Autowired 
private UserDetailsService userDetailsService; 

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

에 대한 빈을 추가

@Service

@Service ("UserDetailsService의")

관련 문제