1

快速回答:将 Spring Framework 更新到至少 4.0.4

Spring Data Commons这对我来说听起来像是一个错误。根据顺序@EnableSolrRepositories@EnableJpaRepositoriesSpring 尝试设置solrOperationsonJpaRepositoryFactoryBeanentityManageron SolrRepositoryFactoryBean

EnableSolrRepositoriesEnableJpaRepositories

@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

EnableJpaRepositoriesEnableSolrRepositories

@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)。有人遇到过同样的问题吗?

4

1 回答 1

1

快速回答Spring Framework:至少更新到 4.0.4

长答案:在调试存储库初始化后,我得出的结论是,根本原因是 AnnotationReadingVisitorUtils#getMergedAnnotationAttributesAnnotationRepositoryConfigurationSource.

此方法接收在 MyConfig 类上设置的所有注释,并应返回注释属性EnableJpaRepositoryEnableSolrRepository。在这种情况下, 的所有属性都EnableJpaRepository被覆盖,EnableSolrRepository反之亦然。

有关详细信息,请参阅SPR-11649。此问题已在版本 4.0.4 中修复

于 2014-07-13T20:40:58.367 回答