首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring数据JPA依赖关系错误

Spring数据JPA依赖关系错误
EN

Stack Overflow用户
提问于 2017-02-01 22:27:48
回答 3查看 1.3K关注 0票数 2

有人能帮助我正确的字符串引导依赖与字符串-jpa工作吗?我的问题是当我使用下面的gradle依赖项配置时,我会得到一个错误

代码语言:javascript
复制
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework:spring-orm:4.2.4.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.10.5.RELEASE'
compile 'org.hibernate:hibernate-core:5.0.6.Final'
compile 'org.hibernate:hibernate-entitymanager:5.0.6.Final'
compile 'org.apache.tomcat:tomcat-dbcp:8.0.30'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4:2.1.2.RELEASE'

错误

代码语言:javascript
复制
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private gh.gov.moh.admissionsportal.service.UserService gh.gov.moh.admissionsportal.config.SecurityConfig.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private gh.gov.moh.admissionsportal.dao.UserDao gh.gov.moh.admissionsportal.service.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/query/QueryByExampleExecutor
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:661) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 31 common frames omitted

但是当我使用下面的配置时,它可以正常运行,但是在我的Dao配置中使用@Query注释和JPQL时会遇到"NullPointerException in AbstractStringBasedJpaQuery“问题。

代码语言:javascript
复制
@Repository
public interface ExamsDao extends CrudRepository<Exams,Long>{
    @Query("select e from Exams e where e.user.id=:#{principal.id}")
    List<Exams> findAll();
}
代码语言:javascript
复制
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework:spring-orm:4.2.4.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.9.6.RELEASE'
compile 'org.hibernate:hibernate-core:5.0.6.Final'
compile 'org.hibernate:hibernate-entitymanager:5.0.6.Final'
compile 'org.apache.tomcat:tomcat-dbcp:8.0.30'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4:2.1.2.RELEASE'
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-02-01 22:37:02

基于规范- 示例

您的查询应该如下所示:

代码语言:javascript
复制
@Query("select e from Exams e where e.user.id= ?#{principal.id}")

当您引用传递给方法的参数时,将使用:。但在您的方法中没有任何参数。

票数 1
EN

Stack Overflow用户

发布于 2017-02-01 23:44:03

使用Spring包含Spring数据的正确方法是使用spring-boot-starter-data-jpa启动器。删除spring-data和hibernate依赖项并替换如下:

代码语言:javascript
复制
dependencies {
 compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
 compile 'org.springframework.boot:spring-boot-starter-data-jpa'
 compile 'org.apache.tomcat:tomcat-dbcp:8.0.30'
 compile 'org.springframework.boot:spring-boot-starter-security'
 compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4:2.1.2.RELEASE'
}

有关详细信息,请参阅指南

票数 1
EN

Stack Overflow用户

发布于 2017-02-01 22:40:08

根据弹簧APIQueryByExampleExecutor是在1.12中添加的。你似乎引用了1.9.6.RELEASE。您应该升级到1.12.1.RELEASE,或者考虑使用2.0.0.M1版本。

这至少可以解决你的ClassNotFoundException问题。可能还会出现其他异常,因为其他依赖项与最新的Spring Data版本不兼容。

有时,您可以在种子项目(如 )中获得一个有效的依赖项配置(只是一个例子)。否则,拉出每个库并注意错误,或者将所有库拉到最新版本(如果您的源代码仍然使用最新的库)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41991014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档