有人能帮助我使用与string-jpa一起使用的正确的String-boot依赖吗? 我的问题是当我使用下面的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时,我在AbstractStringBasedJpaQuery中遇到了“NullPointerException”。
@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'
答案 0 :(得分:1)
基于spec- examples
您的查询应如下所示:
@Query("select e from Exams e where e.user.id= ?#{principal.id}")
当您引用传递给方法的参数时使用:
但您的方法中没有任何参数。
答案 1 :(得分:1)
使用Spring Boot包含Spring Data的正确方法是使用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'
}
有关详细信息,请参阅guide。
答案 2 :(得分:0)
根据Spring API,QueryByExampleExecutor
中添加了1.12
。您似乎引用了1.9.6.RELEASE
。您应升级到1.12.1.RELEASE
或考虑转到2.0.0.M1
版本。
至少应该解决你的ClassNotFoundException
问题。可能会引发其他异常,因为其他依赖项与最新的Spring Data
版本不兼容。
有时您可以在种子项目中获得工作依赖项配置,例如this(仅举例)。否则,请拉出每个单独的lib并注意错误,或将所有库提取到最新版本(如果您的源代码仍然使用最新的库)