簡體   English   中英

如何解決 Spring-Boot Repository 的“Specified class is an interface”錯誤?

[英]How to resolve "Specified class is an interface" error for Spring-Boot Repository?

我有一個 Spring-Boot 應用程序。 我還編寫了這個應用程序使用的 Spring-Boot 庫。 我在這個 spring-boot 應用程序中使用 JPARepository。 同理,我使用的庫中有JpaRepository。 我使用 @EnableJpaRepositories 注釋來激活我使用的庫中的存儲庫。 它看起來與下面的完全一樣。

@Slf4j
@Aspect
@Configuration
@RequiredArgsConstructor
@EntityScan(basePackages = {"a.b.c.entity"})
@EnableJpaRepositories(basePackages = {"a.b.c.repository"})
@EnableConfigurationProperties(ServiceResponderProperties.class)
@ConditionalOnProperty(prefix = PREFIX, name = "enabled", havingValue = "true")
public class ResponderAspect {
    protected final ResponderRepository responderRepository;
    ... //some code
}

我的存儲庫界面如下所示:

public interface ResponderRepository extends CrudRepository<Responder, Long> {
    List<Responder> getByCode(String code);
}

我將此項目添加到我的 pom.xml 文件中,然后當我運行我的主應用程序時,但現在我收到以下關於我作為啟動主應用程序的 maven 包添加的庫的錯誤。

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [a.b.c.ResponderRepository]: Specified class is an interface
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:70)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295)
... 22 common frames omitted

您是否嘗試在 ResponderRepository 接口上添加 @Repository 注釋?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM