简体   繁体   English

Spring Boot + Apache CXF:为什么找不到wsdl?

[英]Spring Boot + Apache CXF: why can't find wsdl?

Collegues, I am still trying "to make friends all" Spring-Boot, Tomcat and web service implementation class: 同事,我仍在尝试“结识所有人” Spring-Boot,Tomcat和Web服务实现类:

@javax.jws.WebService(
                      serviceName = "ServiceForApp",
                      portName = "ServiceEndPoind",
                      targetNamespace = "http://new.webservice.namespace",
                      endpointInterface = "com.comp.appserv.WebServiceInterface",
                          wsdlLocation = "resources/WebService.wsdl"
                          )

public class ServiceEndPoindImpl implements WebServiceInterface {logic};

I have an application class: 我有一个应用程序类:

package com.comp.config;


import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import com.comp.appserv.ServiceEndPoindImpl;

import javax.xml.ws.Endpoint;


@SpringBootApplication
public class Application  {

    public static final String SERVLET_MAPPING_URL_PATH = "/soap/*";
    public static final String SERVICE_NAME_URL_PATH = "/app";

    @Autowired
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), SERVLET_MAPPING_URL_PATH);
    }


    @Bean(name = Bus.DEFAULT_BUS_ID)
    // <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus">
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    // <jaxws:endpoint id="app" implementor="com.dlizarra.app.ws.AppImpl" address="/app">
    public Endpoint app() {
        Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);
        Object implementor = new ServiceEndPoindImpl();
        EndpointImpl endpoint = new EndpointImpl(bus, implementor);
        endpoint.publish(SERVICE_NAME_URL_PATH);
        return endpoint;
    }
}

And my aim is to get single jar file with embedded Tomcat and web service deployed on it. 我的目标是获得带有嵌入式Tomcat和Web服务的单个jar文件。 Currently my problem is that after mvn spring-boot:run i receive exception 当前我的问题是在mvn spring-boot:run我收到异常

Caused by: java.io.FileNotFoundException: C:\Users\Maya\git\web-services\resources\WebService.wsdl (The system cannot find the file specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)


The full stacktrace is here: http://pastebin.com/Ez3S5CWu

Could you help me with the answers for the next questions: 您能否为我提供下一个问题的答案:

  1. Why Spring try to find wsdl via this link C:\\Users\\Maya\\git\\web-services\\resources\\WebService.wsdl , but not from the path from @javax.jws.WebService annotation? 为什么Spring尝试通过此链接C:\\Users\\Maya\\git\\web-services\\resources\\WebService.wsdl来找到wsdl,而不是从@javax.jws.WebService批注的路径中找到? Where should I set up this path? 我应该在哪里设置此路径?

  2. Is it right approach to create single jar with embedded Tomcat? 用嵌入式Tomcat创建单个jar是否正确?

Spring is using the path from the annotation; 春天使用从标注的路径; but as it is a relative path, the current directory (where your app is started rom ) is used to build the full path. 但由于它是相对路径,因此使用当前目录(您的应用程序从rom启动)。

Try 尝试

wsdlLocation = "classpath:resources/WebService.wsdl"

to search through the classpath. 在类路径中搜索。

As for question 2, is it the right approach to start with so long as nothing prevents it. 至于问题2,只要没有阻止它的方法,从头开始是正确的方法吗? Your IT infrastructure might veto it for some reasons. 您的IT基础结构可能由于某些原因而否决了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM