![](/img/trans.png)
[英]Spring Boot + Apache CXF. Publish endpoints with annotations only
[英]Spring Annotations in Apache cxf
我需要將基於apache cxf的注釋移動到spring類,是否有任何簡單的方法來支持相同的Eg。 移出下面的xml中提到的jaxrs:server和“ import resource”移到任何spring配置類
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<!-- This is where we tell which beans CXF should expose as Web-Services -->
</jaxrs:serviceBeans>
</jaxrs:server>
</beans>
要完成@gmalowski的配置類,請刪除jaxRsServer()方法,使該類實現ApplicationContextAware,然后添加
@Bean
public SpringJAXRSServerFactoryBean jaxRsServer() {
SpringJAXRSServerFactoryBean bean = new SpringJAXRSServerFactoryBean();
bean.setAddress("/");
bean.setServiceBeans(new ArrayList<Object>(context.getBeansOfType(FooBar.class).values()));
//bean.setProviders(Collections.singletonList(jacksonProvider()));
bean.setApplicationContext(context);
bean.create();
return bean;
}
private ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext;
}
為了導入資源,您可以簡單地使用@ImportResouce注釋。
你的例子是
@ImportResource(locations = {"classpath:META-INF/cxf/cxf.xml", "classpath:META-INF/cxf/cxf-servlet.xml"})
對於JAX-RS servlet,您可以執行以下操作:
@Configuration
@ImportResource({"classpath:META-INF/cxf/cxf.xml"})
public class JaxRsProvidedByApacheCXFConfiguration {
@Value("${cxf.path:/*}")
private String cxfPath;
@Bean
public ServletRegistrationBean cxfServletRegistrationBean() {
return new ServletRegistrationBean(new CXFServlet(), cxfPath);
}
@Bean
public Server jaxRsServer() {
return null; // todo create the server with JAXRSServerFactoryBean
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.