更新时间:2023-09-12 19:55:58
您需要在API中注释您的API serviceBean,带有 javax.ws.rs
的注释,表示HTTP方法,如 GET
, PUT
, POST
, DELETE
等。这会将您的API暴露给您的JAX-RS服务器将需要在CXF配置XML中创建。这样的事情 -
You will need to annotate your APIs in the serviceBean with javax.ws.rs
based annotations representing HTTP methods like GET
, PUT
, POST
, DELETE
, etc. This will expose your APIs to the JAX-RS server you will need to create in CXF configuration XML. Something like this -
<jaxrs:server id="base" address="/">
<jaxrs:providers>
<ref bean="provider1" />
<ref bean="provider2" />
</jaxrs:providers>
<jaxrs:serviceBeans>
<ref bean="serviceBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
此配置文件与<上下文中提到的文件相同-param>
web.xml中的contextConfigLocation
This configuration file is the same one that gets mentioned as the <context-param>
contextConfigLocation in your web.xml
如果您不使用Spring,可以创建JAX-RS服务器以编程方式使用:
In case you are not using Spring, the creation of the JAX-RS server can be done programmatically using:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(abc.class);
List providers = new ArrayList();
sf.setProviders(providers);
sf.setAddress(ENDPOINT_ADDRESS);
server = sf.create();
但是我没有看到没有Spring使用CXF的意义。
But I don't see the point of using CXF without Spring.