gpt4 book ai didi

spring-boot - Spring Boot Apache CXF JAX-RS 服务上下文路径/基本 URI

转载 作者:行者123 更新时间:2023-12-02 15:09:05 25 4
gpt4 key购买 nike

我像这样在 Spring Boot 中配置我的 JAXRS 服务器:

    JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();
factoryBean.setBus(this.bus);
factoryBean.setFeatures(singletonList(swagger2Feature()));
factoryBean.setServiceBeans(Arrays.asList(blah(), blah2(), blah3()));
factoryBean.setAddress("/api/v1/"); // HERE

List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
factoryBean.setProviders(providers);

BindingFactoryManager manager = factoryBean.getBus().getExtension(BindingFactoryManager.class);
JAXRSBindingFactory restFactory = new JAXRSBindingFactory();
restFactory.setBus(factoryBean.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, restFactory);

return factoryBean.create();

但是,URL 前面总是需要 /services,这很麻烦(但不是世界末日)。有什么方法可以删除 /services 并将其部署到根上下文吗?

最佳答案

如果您还没有创建自己的 CxfServlet bean,您可以通过在 application.properties 文件中设置 cxf.path 属性来设置路径

cxf.path=/

另一种方法是覆盖ServletRegistrationBean

@Bean
public ServletRegistrationBean cxfServletRegistration() {
String urlMapping = "/*";
ServletRegistrationBean registration = new ServletRegistrationBean(
new CXFServlet(), urlMapping);
registration.setLoadOnStartup(-1);
return registration;
}

关于spring-boot - Spring Boot Apache CXF JAX-RS 服务上下文路径/基本 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45038705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com