java - 无法 Autowiring CRUD 存储库

标签 java spring spring-data-jpa autowired

我有与 crud 存储库的接口(interface):

public interface LekarDao extends  CrudRepository<Lekarfizo, Long> {

     Lekarfizo findByBrojLicence(String brojLicence);
  }

我有服务:

@Service
@Transactional
public class LekarDaoImpl {

@Autowired
private LekarDao lekarDao;


 public Lekarfizo nadjipoIdu(String jmbg){

   return lekarDao.findByBrojLicence(jmbg);
 }

我的 xml:

 <context:annotation-config />
<context:component-scan base-package="com.dao" />
 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
   <jpa:repositories base-package="com.dao"/>
 <bean id="entityManagerFactory"   class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
 <property name="persistenceUnitName" value="ProjekatOrdPU" />
</bean>

<bean id="transactionManager"class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
 <tx:annotation-driven transaction-manager="transactionManager" />

我有错误:

引起:org.springframework.beans.factory.BeanCreationException:无法 Autowiring 字段:private com.dao.LekarDao com.dao.LekarDaoImpl.lekarDao;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“lekarDao”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/data/repository/query/QueryByExampleExecutor

我真的不知道我做错了什么。 我使用 Spring 4.0.1,spring-data-jpa 1.10.1,spring-data-commons 1.10.0。

最佳答案

QueryByExampleExecutor 的 Javadoc 指出此接口(interface)已从 v1.12 添加到 spring-data-commons,因此看起来 spring-data-jpa 1.10 依赖于 spring-data-commons 1.12 而不是 1.10,因为你目前有。

http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/query/QueryByExampleExecutor.html

public interface QueryByExampleExecutor Interface to allow execution of Query by Example Example instances. Since: 1.12

虽然您没有使用 Maven,但您可以通过查看 spring-data-jpa 1.10 JAR 文件来确认任何依赖项的所需版本。在文件 META-INF/maven/org.springframework.data/spring-data-jpa/pom.xml 中。

它具有以下属性集:

<springdata.commons>1.12.1.RELEASE</springdata.commons>

除了最简单的项目之外,手动管理依赖项将变得极其困难。您应该考虑使用 Maven 或 Gradle 等构建工具。

关于java - 无法 Autowiring CRUD 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37030617/

相关文章:

java - Eclipse 版本 3.6.1 : where might jar names be referenced other than . 类路径文件?

java - 奇怪的故障 Flappy Bird 代码

java - Spring Data Rest 添加到根的链接 - RepositoryLinksResource 无法转换为 Resource

java - 参数化 JPA 入站 channel 适配器

java - Spring 配置问题 - 无法加载应用程序类

Java 类和子类逻辑

Java spring bean配置错误

java - 环境变量中的数据库名称

java - Spring Boot 2 MultiProject Build 忽略子项目中的 application.yml

Spring Data Rest 同一对象的不同数据取决于 uri/files <-> files/1