我有与 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,因为你目前有。
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/