0

をautowiredすることはできません私は春ブーツにセキュリティ設定を追加すると、私はこの迷惑なエラーになった:春のブートのセキュリティは@Repository

 
2017-05-18 15:23:29.160 WARN 1806 --- [   main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsServiceImpl': Unsatisfied dependency expressed through field 'userRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#236c098' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#236c098': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'chatController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException 

これはspringBootApplicationです:

public class Ailab4finalApplication { 

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

    @Bean 
    public MessageSource messageSource() { 
     ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); 
     messageSource.setBasename("validation"); 
     return messageSource; 
    } 
} 

これがされスプリングブートセキュリティの構成:

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 
    @Autowired 
    private UserDetailsService userDetailsService; 

    @Autowired 
    private Environment env; 

    @Bean(name="passwordEncoder") 
    public PasswordEncoder getPasswordEncoder() { 
     return new BCryptPasswordEncoder(); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .authorizeRequests() 
        .antMatchers("/webjars/**", "/css/**", "/registration", "/", "/home").permitAll() 
        .anyRequest().authenticated() 
        .and() 
       .formLogin() 
        .loginPage("/login") 
        .permitAll() 
        .and() 
       .logout() 
        .permitAll(); 
     http.csrf().disable(); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth.userDetailsService(userDetailsService).passwordEncoder(getPasswordEncoder()); 
    } 
} 

この春ブーツでautowiredすることができないようだuserRepository

@Repository 
public interface UserRepository extends CrudRepository<UserHibernate, Long> { 
    @Query("select u from UserHibernate u where u.email = ?1") 
    public UserHibernate findByEmail(String email); 

    @Query("select u from UserHibernate u where u.nickname = ?1") 
    public UserHibernate findByNickname(String nickname); 

    @Query("select u from UserHibernate u where u.id = ?1") 
    public UserHibernate findById(Long id); 
} 

そして最後に、これは私のプロジェクトツリーです:

src: 
    -Ailab4finalApplication.java 
    -DatabaseConfig.java 
    -SecurityConfig.java 
src/services: 
    -SecurityService.java 
    -SecurityServiceImpl.java 
    -UserDetailsServiceImpl.java 
    -UserService.java 
    -UserServiceImpl.java 
src/jpa_repositories: 
    -SecurityService.java 
    -SecurityServiceImpl.java 
    -UserDetailsServiceImpl.java 
    -UserService.java 
    -UserServiceImpl.java 
+1

あなたの 'UserDetailsS​​erviceImpl'はどのように見えますか?それは 'org.springframework.security.core.userdetails.UserDetailsS​​ervice'を実装していますか? – pvpkiran

+1

完全なスタックトレースを送信します。 –

+0

'@ SpringBootApplication'? – Jaiwo99

答えて

0

私はすべてのSecurityconfingにオートワイヤリングすることによって、問題を解決します私が使ったサービスとレポジトリです。

関連する問題