简体   繁体   中英

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

I have a Spring-Boot application. I also wrote a Spring-Boot library that this application uses. I am using JPARepository in this spring-boot application. In the same way, there are JpaRepository in the library I use. I use the @EnableJpaRepositories annotation to activate the repository in the library I use. It looks exactly like the one below.

@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
}

My repository interface looks like this:

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

I add this project to my pom.xml file and then when I run my main application, But now I'm getting the following error about the library I added as the maven package that I started my main application with.

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 注释?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM