Spring Data JPA 'jpaMappingContext' 错误,IllegalStateException:预期能够解析类型但得到 null [英] Spring Data JPA 'jpaMappingContext' error, IllegalStateException: Expected to be able to resolve a type but got null
问题描述
我正在使用 Spring Data JPA 5.0.4 并收到此错误:
I am using Spring Data JPA 5.0.4 and am getting this error:
创建名为myRepository"的 bean 时出错:无法解析设置 bean 属性时引用 bean 'jpaMappingContext''映射上下文';嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建名为jpaMappingContext"的 bean:调用 init 方法失败;嵌套异常是 java.lang.IllegalStateException: Expected能够解析类型但得到空值!这通常源于实现原始 Map 或 Collection 接口的类型!在...
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...
这是我的 myRepository
bean:
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);
}
这里是我如何扫描 applicationContext.xml
中的 bean:
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" />
推荐答案
我遇到了同样的问题,这是因为我的实体具有 Map
类型的属性.只需将其更改为 HashMap
或类似的.
I had the same issue and it was because my entity has an attribute of type Map
. Just change it for HashMap
or similar.
这篇关于Spring Data JPA 'jpaMappingContext' 错误,IllegalStateException:预期能够解析类型但得到 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!