1
我目前正在测试spring data rest,并且我想通过REST接口公开我的实体的主键(id)。 (?)Spring bean GeoModule bean注入到RepositoryRestMvcConfiguration
我已经找到了正确的方式做,这就是:
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豆,所以它不能自动装配它的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个?
对我来说,即使使用** @ Configuration **注释,它也不起作用。 – 2015-03-22 17:32:36
我问了这个问题已经有一段时间了,所以我完全不记得解决方案。 你有任何XML配置(子类或原始?) – SzaboAdam 2015-03-23 18:17:00