Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot security无法自动连接@Repository_Spring_Hibernate_Spring Boot_Spring Security_Spring Repositories - Fatal编程技术网

Spring boot security无法自动连接@Repository

Spring boot security无法自动连接@Repository,spring,hibernate,spring-boot,spring-security,spring-repositories,Spring,Hibernate,Spring Boot,Spring Security,Spring Repositories,当我在spring boot中添加安全配置时,我遇到了一个恼人的错误: 2017-05-18 15:23:29.160 WARN 1806 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factor

当我在spring boot中添加安全配置时,我遇到了一个恼人的错误:

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 这是spring引导安全性的配置:

这是一个似乎无法通过Spring boot自动连接的用户存储库:

@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);
}

我通过自动连接到SecurityConfig中来解决这个问题。我使用了所有的服务和存储库。

您的
UserDetailsServiceImpl
看起来怎么样?它是否实现了
org.springframework.security.core.userdetails.userdetails服务
?发布完整的堆栈跟踪。
@SpringBootApplication
?在此处添加您的userdetails服务实现
@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());
    }
}
@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