【问题标题】:JAX-WS Endpoint bean creation fails with ServiceConstructionExceptionJAX-WS Endpoint bean 创建失败并出现 ServiceConstructionException
【发布时间】:2016-07-18 11:07:23
【问题描述】:

我正在尝试使用spring-boot 发布webservice

这是我的设置方式。

我有一个interface 有一些methods

@WebService
public interface FirstInterface
{
    @WebMethod
    void method1(@WebParam(name = "id") String id);
    void method2(@WebParam(name = "id2") String id);
}

我还有另一个interface,还有更多methods 它扩展了FirstInterface

@WebService
public interface SecondInterface extends FirstInterface
{
    @WebMethod
    void method3(@WebParam(name = "id") String id);
    void method4(@WebParam(name = "id2") String id);
}

现在我有一个实现类,它实现了SecondInterface 并且有一个endpointInterface 指的是我的SecondInterface 是这样的:

@Service
@WebService(endpointInterface = "com.somepackage.SecondInterface")
public class CallBackServicesImpl implements SecondInterface
{
    @Override
    //override all four methods here
}

现在我有一个发布这些服务的配置类

@Configuration
public class WebServiceConfig
{
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), serviceImpl());
        endpoint.publish(SERVICE_NAME_PATH);
        return endpoint;
    }

}

问题:webservice 使用此设置发布,endpointinterface 指向 FirstInterface,但只有两种方法可供使用。

现在我都希望有四种方法可供客户端使用,所以我将endpointinterface 指向SecodInterface,它开始抛出异常说Error creating bean with name 'endpoint',org.apache.cxf.service.factory.ServiceConstructionException

我在这里缺少一些基本的东西吗?我怎样才能实现这种行为?

【问题讨论】:

    标签: web-services spring-boot cxf jax-ws


    【解决方案1】:

    删除impl类上的@WebService注解

    这是工作副本

    FirstInterface.java

    @WebService
    public interface FirstInterface {
    
        @WebMethod
        void method1(@WebParam(name = "id") String id);
        @WebMethod
        void method2(@WebParam(name = "id2") String id);
    
    }
    

    SecondInterface.java

    @WebService
    public interface SecondInterface extends FirstInterface {
    
        @WebMethod
        void method3(@WebParam(name = "id") String id);
    
        @WebMethod
        void method4(@WebParam(name = "id2") String id);
    
    }
    

    实现类

    @Service
    public class KPImpl implements SecondInterface {
    
        public static final Logger LOG = LoggerFactory.getLogger(KPImpl.class);
    
        @Override
        public void method3(String id) {
    
            LOG.info("Method3 {}", id);
    
        }
    
        @Override
        public void method4(String id) {
            LOG.info("Method4 {}", id);
        }
    
        @Override
        public void method1(String id) {
            LOG.info("Method1 {}", id);
    
        }
    
        @Override
        public void method2(String id) {
    
            LOG.info("Method2 {}", id);
    
        }
    
    }
    

    最后配置文件

    @Configuration
    public class WsConfiguration {
    
        @Bean
        public Server getJaxWsServer(SpringBus bus, KPImpl impl) {
    
            final JaxWsServerFactoryBean serverFctry = new JaxWsServerFactoryBean();
            serverFctry.setAddress("/kp");
            serverFctry.setServiceBean(impl);
            serverFctry.setServiceClass(KPImpl.class);
            serverFctry.getFeatures().add(new LoggingFeature());
            return serverFctry.create();
        }
    
    }
    

    【讨论】:

    • 这也不起作用,同样的例外。除了我真正不明白的是,我的做法有什么问题。
    • 我们能看到 pom.xml 吗?
    • 我有 cxf-rt-frontend-jaxwscxf-rt-transports-http 依赖项以及所需的 sprint-boot 依赖项。奇怪的是,如果 endpointinterface 指的是 FirstInterface,它就可以工作。
    • 不确定你为什么会得到完整的堆栈跟踪会有所帮助。
    • 我已经解决了,接口方法的返回类型之一存在问题,导致端点创建失败。这是一个愚蠢的错误。异常不清楚,所以花了很多时间来捕捉它。不过感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2016-07-13
    • 2011-03-16
    • 2015-10-12
    • 2014-08-29
    • 1970-01-01
    • 2016-01-26
    • 2013-03-09
    • 2010-12-15
    相关资源
    最近更新 更多