1

作为了解 JAX-WS 和 CXF 的练习,我决定实现一个计算 BMI 的小型服务。它基于本教程

我会假设只使用我在 xml 端点定义中指定的地址,但实际上 jboss 也使它在其他地方可用。

我得到相同的服务,两者都可用

http://localhost:8080/BMI/BmiCalculatorService 

并且在

http://localhost:8080/BMI/services/cxfBmi.

任何人都可以帮忙吗?

这是我的 web.xml:

<web-app>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/beans.xml</param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-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>
</web-app>

这是我的 beans.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.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-servlet.xml" />    

<jaxws:endpoint id="calcBMI"
                implementor="com.company.bmi.services.BMICalculatorImpl"
                address="/cxfBmi"/>

</beans>

接口定义:

package com.company.bmi.services;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface BMICalculator {

public double computeBMI(@WebParam(name="weight") double weight, @WebParam(name="height") double height) ;

}

以及服务的实现:

package com.company.bmi.services;

import javax.jws.WebService;


@WebService(endpointInterface="com.company.bmi.services.BMICalculator", serviceName="BmiCalculatorService") 
public class BMICalculatorImpl implements BMICalculator {

    @Override
    public double computeBMI(double weight, double height) {
        return weight / (height * height);
    }

}

在 Jboss 的日志中,我看到我提到的第一个 URL 确实是设置为服务的发布地址的那个。然后它变成我在 xml 文件中指定的那个。问题是第一个地址仍然有效,我认为这是不正确的。

但是后来在日志中服务器也抱怨找不到服务的观察者,所以我想知道这是否是导致不良结果的原因?

这是日志示例:

10:29:39,326 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] (MSC service thread 1-5) Add Service
id=com.company.bmi.services.BMICalculatorImpl
address=http://localhost:8080/BMI/BmiCalculatorService
implementor=com.company.bmi.services.BMICalculatorImpl
invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker
serviceName={http://services.bmi.company.com/}BmiCalculatorService
portName={http://services.bmi.company.com/}BMICalculatorImplPort
wsdlLocation=null
mtomEnabled=false
10:29:39,441 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-5) Creating Service {http://services.bmi.company.com/}BmiCalculatorService from class com.company.bmi.services.BMICalculator
10:29:39,748 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-5) Setting the server's publish address to be http://localhost:8080/BMI/BmiCalculatorService
10:29:39,832 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-5) WSDL published to: file:/zimory/jboss/switchyard-as7-0.5/standalone/data/wsdl/BMICalculator-0.0.1-SNAPSHOT.war/BmiCalculatorService.wsdl
10:29:39,836 INFO  [org.jboss.as.webservices] (MSC service thread 1-2) JBAS015539: Starting service jboss.ws.port-component-link
10:29:39,844 INFO  [org.jboss.as.webservices] (MSC service thread 1-4) JBAS015539: Starting service jboss.ws.endpoint."BMICalculator-0.0.1-SNAPSHOT.war"."com.company.bmi.services.BMICalculatorImpl"
10:29:39,847 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-4) register: jboss.ws:context=BMI,endpoint=com.company.bmi.services.BMICalculatorImpl
10:29:39,849 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016008: Starting weld service for deployment BMICalculator-0.0.1-SNAPSHOT.war
10:29:40,077 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/BMI]] (MSC service thread 1-5) Initializing Spring root WebApplicationContext
10:29:40,078 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization started
10:29:40,091 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-5) Refreshing Root WebApplicationContext: startup date [Fri Mar 15      10:29:40 CET 2013]; root of context hierarchy
10:29:40,111 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from ServletContext resource [/WEB-INF/beans.xml]
10:29:40,138 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
10:29:40,152 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-soap.xml]
10:29:40,162 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-5) Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml]
10:29:40,415 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7cbdc6a3: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,calcBMI]; root of factory hierarchy
10:29:40,498 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-5) Creating Service {http://services.bmi.company.com/}BmiCalculatorService from class com.company.bmi.services.BMICalculator
10:29:40,724 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-5) Setting the server's publish address to be /cxfBmi
10:29:40,730 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization completed in 652 ms
10:29:40,763 INFO  [org.jboss.web] (MSC service thread 1-5) JBAS018210: Registering web context: /BMI
10:29:40,874 INFO  [org.jboss.as.server] (management-handler-thread - 2) JBAS018559: Deployed "BMICalculator-0.0.1-SNAPSHOT.war" [2013-03-15 10:29:40,895] Artifact BMICalculator:war: Artifact is deployed successfully
10:39:07,639 WARNING [org.apache.cxf.transport.servlet.ServletController] (http--127.0.0.1-8080-2) Can't find the the request for http://localhost:8080/BMI/services/cfxBmi/BmiCalculatorService's Observer
4

1 回答 1

1

地址http://localhost:8080/BMI/services/*由显式创建CXFServlet

Whilehttp://localhost:8080/BMI/BmiCalculatorServiceorg.jboss.wsf.stack.cxf.metadata.MetadataBuilder通过隐式注释扫描创建的。

请参阅如何在 JBoss AS 7 中禁用扫描 @WebService 注释?为治愈。

于 2013-03-15T13:03:14.213 回答