Search code examples
springspring-data-restspring-bean

Spring beans GeoModule bean injection to RepositoryRestMvcConfiguration


I'm currently testing spring data rest, and I want to expose the primary keys (ids) of my entities through the REST interface.

I have found that the proper (?) way to do this is:

public class IdExporterConfiguration extends RepositoryRestMvcConfiguration {

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

The problem is, that if I change my bean definition to this:

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

From this:

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

my application fails to start...

The error is:

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)}

Basically it says that it does not find a GeoModule bean, so it can't autowire it for the RepositoryRestMvcConfiguration base...

Now the fun part is, that is I define the bean:

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

The error changes to:

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

So if I don't define a bean, there is 0, but if I define one, there is 2?


Solution

  • I still don't know why, but if I use the @Configuration annotation, then it works... No GeoModule bean needed, but how can it be, that with the original config as XML bean definition it works, but with the subclass, it does not?