Spring Data JPA 'jpaMappingContext' error, IllegalStateException: Expected to be able to resolve a type but got null

20,191

Solution 1

I had the same issue and it was because my entity has an attribute of type Map. Just change it for HashMap or similar.

Solution 2

I had the same exactly problem and I solve it setting @EntityScan(basePackages = {"com.mypackage.entity"})

Share:
20,191
Kingamere
Author by

Kingamere

Updated on July 26, 2022

Comments

  • Kingamere
    Kingamere almost 2 years

    I am using Spring Data JPA 5.0.4 and am getting this error:

    Error creating bean with name 'myRepository': Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Expected to be able to resolve a type but got null! This usually stems from types implementing raw Map or Collection interfaces! at...

    This is my myRepository bean:

    @Repository
    public interface MyRepository extends CrudRepository<MyEvent, Long> {
    
        List<MyEvent> findAll();
    
        MyEvent save(MyEvent persisted);
    
        Optional<MyEvent> findById(Long id);
    
        Optional<MyEvent> findByMyEventId(long id);
    
        List<MyEvent> findByCurrentActivityTypeCd(BigDecimal id);
    
        List<MyEvent> findByCity(String city);
    }
    

    Here is how I scan the beans in applicationContext.xml:

       <context:annotation-config />
       <context:spring-configured />
       <aop:aspectj-autoproxy />
    
       <tx:annotation-driven />
    
       <context:component-scan base-package="com.my.service, com.my.repository" />
    
  • Gabriel Brito
    Gabriel Brito almost 4 years
    if someone else is search the answer for kotlin: stackoverflow.com/a/44213463/5749192
  • njari
    njari about 2 years
    Can you specify where exactly you added this annotation? On the Datasource configuration class? Or the Spring Application main class?