spring data jpa repository inject fails using @Autowired in spring boot

后端 未结 2 1774
眼角桃花
眼角桃花 2020-12-21 09:29

spring boot entry class

package com.test;

@SpringBootApplication(exclude={
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerA         


        
相关标签:
2条回答
  • 2020-12-21 10:18

    You need to provide the package name to Spring to scan the repositories from, using @EnableJpaRepositories annnotation, e.g.:

    @SpringBootApplication
    @EnableJpaRepositories("com.test.assetmanagementdigital.repository")
    public class AssetManagementDigital2Application
    

    Here's the documentation.

    0 讨论(0)
  • 2020-12-21 10:26

    Your Spring configuration is not correct.

    The spring-boot-starter-data-jpa already provides the hibernate-core dependency. While you declare it with a specific version :

    compile group: 'org.hibernate', name: 'hibernate-core', version: '4.2.2.Final'
    

    You have not to declare it a second time as your specified version may be different and not compatible with the version provided by the starter.
    And according to your error, it seems be the case as the javax.persistence.PersistenceContext.synchronization() method is not found at runtime.

    Post-processing of merged bean definition failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;

    Just remove the hibernate-core dependency and it should work.

    0 讨论(0)
提交回复
热议问题