快速回答:将Spring Framework更新至至少4.0.4
这听起来像Spring Data Commons
中的一个错误。
根据{{1}}和@EnableSolrRepositories
的顺序,Spring尝试在@EnableJpaRepositories
上设置solrOperations
或
JpaRepositoryFactoryBean
上的entityManager
。
SolrRepositoryFactoryBean
之前 EnableSolrRepositories
EnableJpaRepositories
结果
@Configuration
@EnableSolrRepositories("package.a")
@EnableJpaRepositories("package.b")
@EnableTransactionManagement
public class MyConfig {
...
}
在Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'solrOperations' of bean class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]: Bean property 'solrOperations' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489)
... 107 more
之前 EnableJpaRepositories
EnableSolrRepositories
结果
@Configuration
@EnableJpaRepositories("package.b")
@EnableSolrRepositories("package.a")
@EnableTransactionManagement
public class MyConfig {
...
}
我正在使用最新的Spring Data版本
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'entityManager' of bean class [org.springframework.data.solr.repository.support.SolrRepositoryFactoryBean]: Bean property 'entityManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:922)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489)
... 77 more
作为旁注
在我使用相同配置类的测试中不会发生此错误:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.6.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
仅在Tomcat上部署期间发生(我的版本为7.0.54)。 有人遇到过同样的问题吗?
答案 0 :(得分:1)
快速回答:将Spring Framework
更新为至少4.0.4
答案很长:
在调试存储库初始化之后,我得出结论,根本原因是一个错误的实现
AnnotationReadingVisitorUtils#getMergedAnnotationAttributes
中使用的AnnotationRepositoryConfigurationSource
方法。
此方法接收在MyConfig类上设置的所有注释,并应返回EnableJpaRepository
或EnableSolrRepository
的注释属性。
在这种情况下,EnableJpaRepository
的所有属性都被EnableSolrRepository
覆盖,反之亦然。
有关详细信息,请参阅SPR-11649。此问题已在4.0.4版中修复