I am trying to use Spring Boot to create an application that has the following:
A 3rd party HttpServlet needs to be mapped at "/data/*" to match the following:
- "/Patient" given as "/data/Patient"
- "/_services/*" given as "/data/_services/something"
Then I need to add a new service option. I wanted to do this using a RestController that was using the request mapping of "/data/_services/smart/".
In addition, I wanted other endpoints like "/health", "/management", to be served by the dispatcher servlet. If I use the default dispatcher servlet mapped at "/" then "/health", "/management" work fine.
If I add a ServletRegistrationBean for the 3rd party servlet, requests like "/data/Patient", etc work fine. @Bean public ServletRegistrationBean data() { HapiFhirServlet servlet = new HapiFhirServlet(myAppCtx, metadataRepository); ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet, "/data/*"); return servletRegistrationBean; }
But I am unable to map the RestController at "/data/_services/smart". I am trying:
@Bean
@Autowired
public ServletRegistrationBean smartServicesRegistrationBean(DispatcherServlet dispatcherServlet) {
return new ServletRegistrationBean(dispatcherServlet, "/data/_services/smart/*");
}
As soon as I add this ServletRegistrationBean, the path "/data/_services/smart/" works, the paths for the 3rd party servlet work, but the other dispatcher requests ("/health", "/management") fail. It seems I can only have dispatcher at either "/" or "/data/_services/smart/" but not both.
Can someone please advise?
Here is my Application class:
@EnableAutoConfiguration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, /*securedEnabled = true, */proxyTargetClass = true)
@Import({OAuth2ResourceConfig.class, MethodSecurityConfig.class})
@ComponentScan
public class HSPCReferenceApiApplication extends SpringBootServletInitializer {
@Autowired
private WebApplicationContext myAppCtx;
@Autowired
private MetadataRepository metadataRepository;
public static void main(String[] args) {
SpringApplication.run(HSPCReferenceApiApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(HSPCReferenceApiApplication.class);
}
@Bean
public ServletRegistrationBean data() {
HapiFhirServlet servlet = new HapiFhirServlet(myAppCtx, metadataRepository);
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet, "/data/*");
return servletRegistrationBean;
}
@Bean
@Autowired
public ServletRegistrationBean smartServicesRegistrationBean(DispatcherServlet dispatcherServlet) {
return new ServletRegistrationBean(dispatcherServlet, "/data/_services/smart/*");
}
}