unsatifieddependencyException:在2.4.1 spring boot中创建名为的bean时出错

ozxc1zmp  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(211)

主要类别:

package *.*.*;

@SpringBootApplication
public class UserApplication {

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

}

dbutils.java文件

package *.*.*.dataaccess.dbutils;
    @Service
    public class DBUtils {

        @Autowired
        UserRepository userRepository;

        public UserEntity getUserEntityById(String id) {

            return userRepository.findById(id);
        }
    }

存储库类:

package *.*.*.dataaccess.repository;

@Repository
public interface UserRepository extends JpaRepository<UserEntity, UserIdentity> {

    UserEntity findById(String id);
}
``` `and also UserEntity java class is in package *.*.*.dataaccess.dao;` ##测试等级:

@SpringBootTest
class UserApplicationTests {

@Autowired 
DBUtils utils; // issue is with this

@Test
void contextLoads() {
}

}

在对整个项目进行maven测试时,出现以下错误:
java.lang.illegalstateexception:未能加载applicationcontext,原因是:org.springframework.beans.factory.unsatifiedDependencyException:创建名为“dbutils”的bean时出错:通过字段“userrepository”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.nosuchbeandefinitionexception:没有类型为“…dataaccess.repository.userrepository”的合格bean可用:至少需要1个符合autowire候选的bean。依赖项注解:{@org.springframework.beans.factory.annotation.autowired(required=true)}由以下原因引起:org.springframework.beans.factory.nosuchbeandefinitionexception:没有可用的“…dataaccess.repository.userrepository”类型的限定bean:至少需要1个符合autowire候选的bean。依赖项注解:{@org.springframework.beans.factory.annotation.autowired(required=true)} `I have used @Service on DBUtils and @Repository on JpaRepository but still getting the above error and using springboot is 2.4.1.` 有人能帮忙吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题