当前位置: 首页 > 知识库问答 >
问题:

[SpringBoot异常]:考虑定义存储库类型的bean

周翰
2023-03-14

主存储库文件

@Repository
public interface myRepository extends JpaRepository<myRepoEntity, Integer>,myRepositoryCustom

==================================自定义存储

public interface myRepositoryCustom {
@Modifying
@Transactional
void updateSomething(SomeDTO someDTO);

}

============================================

定制回购方法的实现

@Repository
public class myRepositoryImpl implements myRepositoryCustom {
@Autowired
private EntityManager entityManager;

@SuppressWarnings({"unchecked", "deprecation"})
@Override
public void updateSomething(SomeDTO someDTO) {
    /**
    */some logic
    **/

}
}

=====================================================

服务等级

@Service
public class SomeServiceClass
{
@Autowired
private myRepository myRepository;

}

在myRepository上遇到异常请考虑定义一个myRepository类型的bean,它并不是在每次启动时都会突然发生。

我尝试在测试服务器上运行多次遇到复制问题这是不一致的尝试添加组件扫描,尽管我的项目在单个根目录中。尝试使用自动安装注释创建Setter以定义Bean

期望bean可能抛出此错误的场景

[2022-03-25 10:42:19.221] [] [] [] [fa060258] [WARN] 
[SpringBootAPPNAME] 
[o.s.c.a.AnnotationConfigApplicationContext.refresh] - Exception 
encountered during context initialization - cancelling refresh 
attempt: 
org.springframework.beans.factory.UnsatisfiedDependencyException:     
Error creating bean with name 'ribbonClientConfiguration': 
Unsatisfied dependency expressed through field 
'propertiesFactory'; nested exception is 
:org.springframework.beans.factory.
BeanCreationNotAllowedException: 
Error creating bean with name 'propertiesFactory': Singleton bean 
creation not allowed while singletons of this factory are in 
destruction (Do not request a bean from a BeanFactory in a 
destroy method implementation!) 



`***************************
 APPLICATION FAILED TO START
 ***************************

 Description:

 Field myRepository in com.myapp.Service.SomeServiceClass 
 required a bean of type 'com.myapp.repository.myRepository' that 
 could not be found.


 Action:

 Consider defining a bean of type 
 'com.myapp.repository.myRepository' in your configuration.

共有1个答案

巫马欣嘉
2023-03-14

为存储库包添加组件扫描

 类似资料:
  • 我有一个Spring Boot项目,其中Flyway与JPA一起使用。 该项目运行完全正常。由于一些要求,我不得不改变Flyway加载的顺序,以便在Hibernate后加载。我搜索并找到了以下解决方案 。我按照上述链接中的答案创建了。现在,当我运行该应用程序时,它会给我以下错误, 现在我对Spring Boot相当陌生,因此无法理解此错误,并且在网上找不到与此错误相关的任何内容。

  • 我得到这个错误。在这种情况下可以做什么? 申请无法启动 说明:com.issuemanagement.service.impl.中构造函数的参数0 Issue历史服务Impl需要一个无法找到的类型为“com.issuemanagement.repository.Issue历史存储库”的bean。 操作:考虑定义“com”类型的bean。问题管理。存储库。配置中的IssueHistoryReposi

  • 在我解释这个问题之前,我已经经历了导致我所面临的错误的类似线程。所以我看了看,没有一个解决方案是有用的,因此,我张贴了我自己的自定义问题。创建简单的Spring Boot/MVC项目时,我遇到以下错误: 说明: 包装中的现场cRepo。网站控制器。LandingPageController需要“pack”类型的bean。网站存储库。找不到CustomerRepository“”。 注入点具有以下注

  • 我对整个Spring的生态系统都是陌生的。我一直在学习一些教程,能够创建一个Spring Boot应用程序并执行crud操作。然后我开始把这个项目改成mybatis的标准。 我已经尝试了许多其他类似问题的答案,但到目前为止没有一个是有效的。 下面是问题陈述: 实现类实现为: 我的Mapper类如下所示: 我的Mapper.xml课是: 最后是我的控制器类: 我得到的错误是: 描述: com.cru

  • 我试图在Spring Boot中创建一个简单的REST服务。在我使用CrudRepository之前,一切都很好。现在我得到了这个错误- ***应用程序启动失败 描述: 公司中的现场er。Spring靴。io。受雇者EmployeeService需要“company”类型的bean。Spring靴。io。受雇者找不到EmployeeRepo“”。 措施: 考虑定义一个“company”类型的bea

  • 我正在做SpringBoot项目,并遵循一些测试SpringBoot的说明。 当我尝试将mysql DB与项目连接时,服务找不到映射器。 我不知道为什么它找不到映射器... 这是服务代码和 这是映射程序代码 下面的错误是 我将发布我的包裹设置的图片。。。