gpt4 book ai didi

java - Jpa存储库 : NoSuchBeanDefinitionException

转载 作者:太空宇宙 更新时间:2023-11-04 09:05:57 25 4
gpt4 key购买 nike

我使用 spring-data-jpa。没有 Spring Boot。

package ru.spb.repository;

public interface CrudUserRepository extends JpaRepository<User, Integer> {
}

存储库。

 package ru.spb.repository;

@Repository
public class UserRepository {

@Autowired
private CrudUserRepository crudRepository;
}

xml 配置文件:

spring-app.xml

<context:component-scan base-package="ru.spb.service"/>
<context:component-scan base-package="ru.spb.repository"/

spring-db.xml:

<context:component-scan base-package="ru.spb.repository" />
<jpa:repositories base-package="ru.spb.repository"/>

在pom中

<spring-data-jpa.version>2.2.0.RELEASE</spring-data-jpa.version>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
</dependency>

但是我明白了:

 NoSuchBeanDefinitionException: No qualifying bean of type 'ru.spb.repository.user.CrudUserRepository' available: expected at least 1 bean which qualifies as autowire candidate

最佳答案

问题已经解决了。我在 web.xml 的 contextConfigLocation 参数值中添加“classpath:spring/spring-db.xml”:

 <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/spring-app.xml
classpath:spring/spring-db.xml
</param-value>
</context-param>

关于java - Jpa存储库 : NoSuchBeanDefinitionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60229993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com