Spring/HAPI FHIR leads to 'NoUniqueBeanDefinitionException: No qualifying bean'

59 Views Asked by At

When the project https://github.com/FirelyTeam/fhirstarters/tree/master/java/hapi-fhirstarters-rest-server-skeleton is wrapped in a Spring application, the server fails to run and displays an org.springframework.beans.factory.NoUniqueBeanDefinitionException error.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'templateEngine' defined in ca.uhn.fhir.to.FhirTesterMvcConfig: Unsatisfied dependency expressed through method 'templateEngine' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver' available: expected single matching bean but found 2: templateResolver,defaultTemplateResolver

This references FhirTesterMvcConfig.templateResolver, which comes from here:

https://github.com/hapifhir/hapi-fhir/blob/ed616f7a6dff2ee891b39f7ed2a301d1efbbfec4/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/FhirTesterMvcConfig.java#L46

It appears that this is related to the use of the HAPI FHIR Web Testpage Overlay, but we cannot figure out how to make the method resolve to a "unique" bean. We have tried adding @Primary annotation to our FhirTesterConfig.java, but the error is unchanged. What can we do differently?

Reproducible example

  1. Clone repo from https://gitlab.com/brsolomon-deloitte/hapi-fhir-overlay-mvce
  2. mvn clean jetty:run

This project is simply the original https://github.com/FirelyTeam/fhirstarters/tree/master/java/hapi-fhirstarters-rest-server-skeleton wrapped in a Spring application, which was in turn created using https://start.spring.io/.

$ tree src
src
└── main
    ├── java
    │   └── ca
    │       └── uhn
    │           └── example
    │               ├── app
    │               │   ├── DemoApplication.java < # New
    │               │   └── ServletInitializer.java < # New
    │               ├── config
    │               │   └── FhirTesterConfig.java
    │               ├── model
    │               │   └── MyOrganization.java
    │               ├── provider
    │               │   ├── OrganizationResourceProvider.java
    │               │   └── PatientResourceProvider.java
    │               └── servlet
    │                   └── ExampleRestfulServlet.java
    ├── resources
    └── webapp
        └── WEB-INF
            └── web.xml

Environment info:

  • HAPI FHIR Version: 6.7.0-SNAPSHOT
  • OS: MacOS 13.5.1
  • Browser: Chrome

Full stack trace is available here: https://gist.github.com/brsolomon-deloitte/92fa3870d7297e2c85b31d7920728c77

0

There are 0 best solutions below