0
的Apache CXF我有下面的類財產注射用彈簧
public class HeaderClass{
@Resource
private WebServiceContext webServiceContext;
public String getUserAgent() {
MessageContext msgCtx = webServiceContext.getMessageContext();
HttpServletRequest request = (HttpServletRequest)msgCtx.get(AbstractHTTPDestination.HTTP_REQUEST);
return request.getHeader("user-agent")
}
在我服務的bean類我要注入該HeaderClass,這樣我就可以如下那裏使用它:
package mypack;
@Path("/MyService")
public class MyServiceClass {
//May be some annotation has to be given here which I don't know
HeaderClass header;
public void useHeader() {
//Code to use the header
System.out.println(header.getUserAgent());
}
}
我有以下里面的beans.xml文件
<jaxrs:server id="SampleService" address="/">
<jaxrs:features>
<cxf:logging />
</jaxrs:features>
<jaxrs:serviceBeans>
<ref bean="MyServiceClass"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="MyServiceClass" class="mypack.MyServiceClass"/>
我不知道如何添加屬性HeaderClass在Bean「MyServiceClass」 我使用apache cxf和spring配置文件(beans.xml)。 請幫忙。實現這一