快速回答:将 Spring Framework 更新到至少 4.0.4
Spring Data Commons
这对我来说听起来像是一个错误。根据顺序@EnableSolrRepositories
和@EnableJpaRepositories
Spring 尝试设置solrOperations
onJpaRepositoryFactoryBean
或
entityManager
on 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 {
...
}
结果是
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
我正在使用最新的 Spring Data 版本
<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>
作为旁注
在我使用相同配置类的测试中不会发生此错误:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {MyConfig.class})
@Transactional
public class MyTest {
....
}
它仅在 Tomcat 上部署期间发生(我的版本是 7.0.54)。有人遇到过同样的问题吗?