Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" />
like image 650
Kingamere Avatar asked May 17 '18 15:05

Kingamere


2 Answers

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

like image 148
Pablo Pirotto Avatar answered Oct 22 '22 09:10

Pablo Pirotto


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

like image 1
Zetared Avatar answered Oct 22 '22 08:10

Zetared