2

Can someone help me with the right String-boot dependency that works with string-jpa? My issue is when i use the below gradle dependency configuration i get an error

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'

Error

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

But when i use the below configuration it runs okay but i get a "NullPointerException in AbstractStringBasedJpaQuery" problems when using the @Query annotation and JPQL in my Dao configuration.

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

3 Answers 3

1

Based on the spec- examples

Your query should look like:

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

The : is used when you referred to a parameter that is passed to the method.. but you do not have any params in your method.

Sign up to request clarification or add additional context in comments.

Comments

1

The correct way to include Spring Data using Spring Boot is with spring-boot-starter-data-jpa starter. Remove spring-data and hibernate dependencies and replace like so:

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

Refer to the guide for more details.

Comments

0

According to the Spring API the QueryByExampleExecutor was added in 1.12. You seem to reference 1.9.6.RELEASE. You should upgrade to 1.12.1.RELEASE or consider to go for the 2.0.0.M1 release.

That should solve your ClassNotFoundException, at least. Possibly other exceptions will raise as other dependencies are incompatible with the newest Spring Data release.

Sometimes you can get a working dependency config in seed projects like this (just an example). Otherwise pull up each single lib and watch out for errors, or pull up all libs to the latest versions (in case your source code still work with the latest libs)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.