Spring DispatcherServlet复杂映射

时间:2016-04-02 16:51:30

标签: spring servlets servlet-mapping

我正在尝试使用Spring Boot创建具有以下内容的应用程序:

第三方HttpServlet需要映射到" / data / *"匹配以下内容:

  • " /病人"以" / data / Patient"
  • 给出
  • " / _服务/ *"以" / data / _services / something"
  • 给出

然后我需要添加一个新的服务选项。我想使用一个使用" / data / _services / smart /"的请求映射的RestController来做到这一点。

此外,我希望调度程序servlet可以提供其他端点,如" / health"," / management"。如果我使用映射在" /"的默认调度程序servlet;那么" / health"," / management"工作得很好。

如果我为第三方servlet添加了ServletRegistrationBean,那么诸如" / data / Patient"等的请求就可以正常工作。     @豆     public ServletRegistrationBean data(){         HapiFhirServlet servlet = new HapiFhirServlet(myAppCtx,metadataRepository);         ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet," / data / *");         return servletRegistrationBean;     }

但是我无法将RestController映射到" / data / _services / smart"。我在尝试:

@Bean
@Autowired
public ServletRegistrationBean smartServicesRegistrationBean(DispatcherServlet dispatcherServlet) {
    return new ServletRegistrationBean(dispatcherServlet, "/data/_services/smart/*");
}

一旦我添加了这个ServletRegistrationBean,路径" / data / _services / smart / "工作,第三方servlet工作的路径,但其他调度员请求(" / health"," / management")失败。似乎我只能在" /"中找到调度员。或" / data / _services / smart / "但不是两个。

有人可以提出建议吗?

这是我的Application类:

@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/*");
}
}

0 个答案:

没有答案