我使用CXF框架開發了JAX-RS webservices,並且我部署在Jboss6中。 雖然我嘗試使用以下URL http://localhost:8080/UPCServiceLayer/services/upcLineOfBusiness/create從我的HTML頁面來訪問應用程序(使用POST方法只)我在服務器控制檯CXF-RS拋出找不到與操作匹配請求路徑/ create的操作,
No operation matching request path /create is found,
下得到下面的錯誤是我cxf.xml
<?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:jaxws="http://cxf.apache.org/jaxws"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:../upc-spring-dao.xml" />
<jaxrs:server id="upcLineOfBusinessRestServiceServer" address="/upcLineOfBusiness">
<jaxrs:serviceBeans>
<ref bean="upcLineOfBusinessRestService" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="upcLineOfBusinessRestService"
class="com.tecnotree.upc.services.restservices.impl.UpcLineOfBusinessRestServiceImpl">
<property name="upcLineOfBusinessDao">
<ref bean="upcLineOfBusinessDao" />
</property>
<property name="upcUserDao">
<ref bean="upcUserDao" />
</property>
</bean>
</beans>
下面是我的資源類
@Path("/")
public classUpcLineOfBusinessRestService {
@POST
@ConsumeMime("application/xml")
@ProduceMime("application/xml")
@Path("/create")
public UpcLineOfBusinessEntity createUpcLineOfBusinessEntity(
UpcLineOfBusinessEntity upcLineOfBusinessEntity)
throws GenericUpcException
和我在web.xml文件中聲明CXF的servlet也。
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
請幫我
謝謝您的回答。我使用@ProduceMime的原因是Jboss6與cxf2.3.1捆綁在一起,在這個版本中我只能使用jsr311-api-0.8-1.3.0.jar。這個jar文件只有MIME類型的舊類。如何將數據發佈爲application/xml?我需要將該HTML頁面的內容類型設置爲application/xml?在這裏,我使用純HTML表單來發布數據。 – Dilip 2012-01-31 10:22:44
暫時我只是將Consumes註釋值更改爲application/x-www-form-urlencoded。之後,我試圖使用HTML表單POST方法調用該資源,但我得到一個新的異常沒有消息正文讀取器找到請求類:UpcLineOfBusinessEntity,ContentType:應用程序/ x-www-form-urlencoded。基於谷歌我明白,我們需要在CXF中配置JAXB。所以我在cxf.xml中添加了以下代碼...... – Dilip 2012-01-31 11:06:58