我能错过什么?

描述:com.solopov.hillel.uquiz.service.UserService中的字段userDAO需要一个无法找到的类型为“com.solopov.hillel.uquiz.dao.UserDAO”的bean . 操作:考虑在配置中定义类型为“com.solopov.hillel.uquiz.dao.UserDAO”的bean .

主要课程:

package com.solopov.hillel.uquiz;

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

@SpringBootApplication
public class UquizApplication {

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

DAO类:

package com.solopov.hillel.uquiz.dao;

        import com.solopov.hillel.uquiz.model.User;
        import org.springframework.data.repository.CrudRepository;
        import org.springframework.stereotype.Repository;

@Repository
public interface UserDAO extends CrudRepository<User,Integer> {
    User findUserByLoginLike(String login);
}

使用DAO的服务类:

@Service
public class UserService {
    @Autowired
    private UserDAO userDAO;


    public boolean addAccount(User user) {
        if (!isRegistered(user)) {
            userDAO.save(user);
            return true;
        }
        return false;
    }
}

GJ

UPD:将注释@EnableJpaRepositories添加到主类后,我收到一个错误:

启动ApplicationContext时出错 . 要显示条件报告,请在启用“debug”的情况下重新运行应用程序 . 2018-07-19 00:26:08.425 ERROR 6810 --- [main] osboot.SpringApplication:应用程序运行失败org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'questionController'的bean时出错:通过字段表示不满意的依赖关系'answerDAO';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'answerDAO'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:接口com.solopov.hillel.uquiz.dao.AnswerDAO at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)~ [spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)〜[spring-beans-5.0.7 . RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE在Org.springframework.beans.factory的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] .support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFacto ry.java:580)~ [spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)~ [spring -beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)~ [spring-beans-5.0.7 .RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~ [spring-beans-5.0.7.RELEASE.jar:5.0.7 . 发布在org.springframework.beans的org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] . orn.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons上的factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE](DefaultListableBea nFactory.java:760)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)〜[spring-context -5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)~ [spring-context-5.0.7.RELEASE.jar:5.0 . 7.RELEASE] org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at org . springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) org.springframework.boot.SpringApplication.run中的[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE](SpringApplication.java:327)[spring-boot-2.0.3.RELEASE.jar:2.0 .3.RELEASE]在org.springfram org.springframework.boot.SpringApplication.run中的ework.boot.SpringApplication.run(SpringApplication.java:1255)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE](SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at com.solopov.hillel.uquiz.UquizApplication.main(UquizApplication.java:12)[classes /:na]引起:org.springframework .beans.factory.BeanCreationException:创建名为'answerDAO'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:接口com.solopov.hillel.uquiz.dao.AnswerDAO at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)~ [spring -beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:581)〜[spring-beans-5.0.7.RELEASE . jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at at org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.beans . factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~ [spring-beans-5.0.7.RELEASE .jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.beans.factory . org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java)中的config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] :1138)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)~ [spring-beans- 5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) 〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] ...省略了19个常见帧引起的:java.lang.IllegalArgumentException:不是托管类型:interface com.solopov.hillel.uquiz . 在org.springframework.data.jpa的org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:473)〜[hibernate-core-5.2.17.Final.jar:5.2.17.Final]的dao.AnswerDAO .repository.support.JpaMetamodelEntityInformation . (JpaMetamodelEntityInformation.java:73)〜[spring-data-jpa-2.0.8.RELEASE.jar:2.0.8.RELEASE] org.springframework.data.jpa.repository.support.JpaEntityInformationSupport .getEntityInformation(JpaEntityInformationSupport.java:66)〜[spring-data-jpa-2.0.8.RELEASE.jar:2.0.8.RELEASE]在org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory . java:181)〜[spring-data-jpa-2.0.8.RELEASE.jar:2.0.8.RELEASE]在org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:119)〜 [ spring 数据-J pa-2.0.8.RELEASE.jar:2.0.8.RELEASE]在org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:102)〜[spring-data-jpa-2.0.8 .RELEASE.jar:2.0.8.RELEASE]在org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:298)〜[spring-data-commons-2.0.8.RELEASE.jar: 2.0.8.RELEASE]在org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda $ afterPropertiesSet $ 3(RepositoryFactoryBeanSupport.java:287)~ [spring-data-commons-2.0.8.RELEASE.jar:2.0 . 8.RELEASE]在org.springframework的org.springframework.data.util.Lazy.getNullable(Lazy.java:141)〜[spring-data-commons-2.0.8.RELEASE.jar:2.0.8.RELEASE] . org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport上的data.util.Lazy.get(Lazy.java:63)〜[spring-data-commons-2.0.8.RELEASE.jar:2.0.8.RELEASE] .afterPropertiesSet(RepositoryFactoryBeanSupport.java:290)〜[spring-data-commons-2.0.8.RELEASE . jar:2.0.8.RELEASE] at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102)~ [spring-data-jpa-2.0.8.RELEASE.jar:2.0.8 .RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704)〜[ spring beans -5.0.7.RELEASE.jar:5.0.7.RELEASE] ... 29个共同帧省略