spring说一个bean已经存在,但是这个bean只是被移到了另一个文件夹中

dgiusagp  于 2021-07-07  发布在  Java
关注(0)|答案(1)|浏览(616)

我刚在我的项目中移动了一些文件,SpringBoot无法运行

.
├── DatabaseLoader.java
├── HomeController.java
├── product
│   ├── Product.java
│   └── ProductRepository.java
├── security
│   ├── JWTAuthenticationFilter.java
│   ├── JWTAuthorizationFilter.java
│   ├── SecurityConstants.java
│   └── WebSecurity.java
├── ShopApplication.java
└── user
    ├── ApplicationUser.java
    ├── ApplicationUserRepository.java
    ├── UserController.java
    └── UserDetailsServiceImpl.java

是因为控制器应该和shopplication(@springbootplication)在同一个文件夹中吗?
spring显示了以下描述:

The bean 'productRepository', defined in com.ecommerce.shop.product.ProductRepository defined in
@EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration,
could not be registered. A bean with that name has already been defined in 
com.ecommerce.shop.ProductRepository defined in @EnableJpaRepositories declared on
JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration and overriding is disabled.

如果没有足够的信息,您可以在这里 checkout 我的github存储库
如蒙关注,我将不胜感激。谢谢您!

w8f9ii69

w8f9ii691#

看来你可能被利用了 @EnableJpaRepositories 多次。在存储库类中,仅使用 @Repository 就够了。

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
}

相关问题