Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonViewSupportFactoryBean required a single bean, but 2 were found #43

Open
markoperic22 opened this issue Mar 15, 2017 · 5 comments
Open

Comments

@markoperic22
Copy link

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

@monitorjbl
Copy link
Owner

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?

@maisonChaves
Copy link

I had the exact same problem, I'm trying to configure this on a spring boot project.

@monitorjbl
Copy link
Owner

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.

@jmesagu1
Copy link

Hello , I am facing the same issue. Did somebody find a way to solve it?

@ThomasJejkal
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants