json-view
json-view copied to clipboard
JsonViewSupportFactoryBean required a single bean, but 2 were found
Hi,
I have problems using this library as I'm getting message:
Description:
Field adapter in com.monitorjbl.json.JsonViewSupportFactoryBean required a single bean, but 2 were found: - requestMappingHandlerAdapter: defined by method 'requestMappingHandlerAdapter' in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class] - repositoryExporterHandlerAdapter: defined by method 'repositoryExporterHandlerAdapter' in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]
What should I do in order to fix this?
Thanks
I don't really have a good answer for this. Spring configurations can be complex, but the root cause is that you've defined a bean twice. Are you importing any other configurations that also define this bean class?
I had the exact same problem, I'm trying to configure this on a spring boot project.
Same answer. It's not really possible for me to debug this for you because Spring configurations can be complex. You've got two places in your code where this bean (RequestMappingHandlerAdapter
) is being picked up. You'll have to step through your Spring configs to figure out where it's coming from.
Hello , I am facing the same issue. Did somebody find a way to solve it?
I've solved this issue by adding the following lines in my Application class:
@Autowired
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
@Bean
@Primary
public RequestMappingHandlerAdapter adapter(){
return requestMappingHandlerAdapter;
}
@Bean
public JsonViewSupportFactoryBean views(){
return new JsonViewSupportFactoryBean();
}
By providing a new RequestMappingHandlerAdapter bean annotated as @Primary
the JsonViewSupportFactoryBean will pick up this bean.
I'm relatively new to Spring so I don't know why my Application is able to select one of the two RequestMappingHandlerAdapter beans and the JsonViewSupportFactoryBean isn't and I also don't know whether this approach has some side effects. So far, everything works fine.