1

現在、Spring Data Rest をテストしており、REST インターフェイスを介してエンティティの主キー (ID) を公開したいと考えています。

これを行う適切な(?)方法は次のとおりです。

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 になりますか?

4

1 に答える 1