Spring Boot : Error creating bean with name 'jpaMappingContext': java.lang.NullPointerException

前端 未结 4 1404
太阳男子
太阳男子 2021-02-07 09:20

My combination of is Spring Boot + Spring Data Jpa + Multiple Databases. I am getting following NullPointer exception when starting the application. Feels like SPring Data with

相关标签:
4条回答
  • 2021-02-07 10:09

    Spring boot have AutoConfiguration classes enabled by default for the data sources allready on classpath. You should explicitly exclude AutoConfiguration class to disable.

    Example :

    @EnableAutoConfiguration(exclude = {JndiConnectionFactoryAutoConfiguration.class,DataSourceAutoConfiguration.class,
                                        HibernateJpaAutoConfiguration.class,JpaRepositoriesAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class})
    @ComponentScan
    public class MyBootApplication {
        public static void main(String[] args) {
            SpringApplication.run(MyBootApplication.class, args);
        }
    }
    
    0 讨论(0)
  • 2021-02-07 10:09

    Many thanks to Vishal for the idea. In my case it was generic-less implementation of javax.persistence.AttributeConverter that provoked this exception. Changing class MapConverter implements AttributeConverter<Map, String> { ... } to class MapConverter implements AttributeConverter<Map<String, Object>, String> { ... } really helped.

    0 讨论(0)
  • 2021-02-07 10:15

    I faced the mentioned issue with mapping in OnetoOne relationship..

    My app had the following OneToOne relationship.

    A ||---|| B
    
    B ||---|| C
    
    Since its OnetoOne, I kept entity B primary key same as entity A, using @MapsId as mentioned here 
    
    https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/
    
    Similarly I kept entity C primary key same as entity B.
    
    

    I fixed this by changing the relationship like this

    A ||---|| B
    
    A ||---|| C
    
    0 讨论(0)
  • 2021-02-07 10:21

    For me this turned out to be due to a custom implementation of org.hibernate.usertype.UserType that I was using for mapping JSON types to Java objects.

    In my particular case, it was mapping to a java.util.Map and this change in Spring Data JPA was causing a regression on upgrading to that version.

    The fix was to explicitly set generic types for the Map - e.g. Map<String, Object> in my case.

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