Spring bean GeoModule bean注入到RepositoryRestMvcConfiguration

时间:2014-10-22 07:56:06

标签: spring spring-data-rest spring-bean

我目前正在测试spring数据休息,我想通过REST接口公开我的实体的主键(ids)。

我发现正确的(?)方法是:

public class IdExporterConfiguration extends RepositoryRestMvcConfiguration {

    @Override
    protected void configureRepositoryRestConfiguration(
            RepositoryRestConfiguration config) {
        super.configureRepositoryRestConfiguration(config);
        config.exposeIdsFor(User.class);
    }
}

问题是,如果我将我的bean定义更改为:

<bean class="test.project.util.IdExporterConfiguration"/>

由此:

<bean class="org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration"/>

我的申请无法启动......

错误是:

Could not autowire field: org.springframework.data.geo.GeoModule org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.geoModule;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.geo.GeoModule] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

基本上它说没有找到GeoModule bean,所以它不能为RepositoryRestMvcConfiguration基础自动装配...

现在有趣的部分是,我定义了bean:

<bean class="org.springframework.data.geo.GeoModule"/>

错误更改为:

Could not autowire field: org.springframework.data.geo.GeoModule org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.geoModule;
nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.data.geo.GeoModule] is defined:
expected single matching bean but found 2: jacksonGeoModule,org.springframework.data.geo.GeoModule#0

所以,如果我没有定义一个bean,那就有0,但是如果我定义了一个bean,那就有2个?

1 个答案:

答案 0 :(得分:0)

我仍然不知道为什么,但是如果我使用@Configuration注释,那么它的工作原理...... 不需要GeoModule bean,但它怎么可能,原始配置作为XML bean定义它可以工作,但是对于子类,它不是吗?