2017-02-01 73 views
2

有人能帮助我正确的字符串引导依赖关系,与字符串j​​pa协同工作吗? 我的问题是,当我使用下面的gradle这个依赖配置我得到一个错误弹簧数据JPA依赖关系错误

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 

但是当我使用它运行好下面的配置,但我得到一个“NullPointerException异常在AbstractStringBasedJpaQuery“在我的Dao配置中使用@Query注释和JPQL时遇到的问题。

@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' 

回答

1

基础上规格 - examples

您的查询应该是这样的:当你提到传递到参数

@Query("select e from Exams e where e.user.id= ?#{principal.id}") 

:使用该方法..但你的方法中没有任何参数。

0

根据Spring APIQueryByExampleExecutor被添加到1.12。你似乎参考1.9.6.RELEASE。你应该升级到1.12.1.RELEASE或考虑去2.0.0.M1版本。

至少应该解决你的ClassNotFoundException。其他例外情况可能会因其他依赖与最新Spring Data版本不兼容而增加。

有时你可以在类似this(只是一个例子)的种子项目中获得工作依赖项配置。否则,拉起每个单独的lib并注意错误,或者将所有库拉到最新版本(如果源代码仍然与最新库一起工作)

1

使用Spring Boot包含Spring Data的正确方法是spring-boot-starter-data-jpa首发。拆卸弹簧的数​​据和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了解更多详情。