我目前正在测试 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,但如果我定义一个,有2?