有人能帮助我正确的字符串引导依赖与字符串-jpa工作吗?我的问题是当我使用下面的gradle依赖项配置时,我会得到一个错误
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'错误
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“问题。
@Repository
public interface ExamsDao extends CrudRepository<Exams,Long>{
@Query("select e from Exams e where e.user.id=:#{principal.id}")
List<Exams> findAll();
}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'发布于 2017-02-01 22:37:02
基于规范- 示例
您的查询应该如下所示:
@Query("select e from Exams e where e.user.id= ?#{principal.id}")当您引用传递给方法的参数时,将使用:。但在您的方法中没有任何参数。
发布于 2017-02-01 23:44:03
使用Spring包含Spring数据的正确方法是使用spring-boot-starter-data-jpa启动器。删除spring-data和hibernate依赖项并替换如下:
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'
}有关详细信息,请参阅指南。
发布于 2017-02-01 22:40:08
根据弹簧API,QueryByExampleExecutor是在1.12中添加的。你似乎引用了1.9.6.RELEASE。您应该升级到1.12.1.RELEASE,或者考虑使用2.0.0.M1版本。
这至少可以解决你的ClassNotFoundException问题。可能还会出现其他异常,因为其他依赖项与最新的Spring Data版本不兼容。
有时,您可以在种子项目(如这 )中获得一个有效的依赖项配置(只是一个例子)。否则,拉出每个库并注意错误,或者将所有库拉到最新版本(如果您的源代码仍然使用最新的库)
https://stackoverflow.com/questions/41991014
复制相似问题