2017-02-01 8 views
2

Может ли кто-нибудь помочь мне с правильной зависимостью String-boot, которая работает со строкой-jpa? Моя проблема, когда я использую конфигурацию ниже Gradle зависимостей я получаю сообщение об ошибкеОшибка Spring 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 "при использовании аннотации @Query и JPQL в моей конфигурации Dao.

@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 (просто пример). В противном случае вытащите каждую отдельную библиотеку и следите за ошибками или вытащите все библиотеки на самые последние версии (в случае, если ваш исходный код по-прежнему работает с последними библиотеками)

1

Правильный способ включения данных Spring с помощью Spring Boot с spring-boot-starter-data-jpa стартер. Удалить пружинные данные и зимуют зависимости и заменить следующий образом:

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 для более подробной информации.