Tomcat下的Spring CXF Soap Web服务:找不到服务

2024-05-13

我正在尝试使用 CXF 和 Spring 设置一个在 Tomcat 上运行的简单 CXF Web 服务:

我有一个 Web 应用程序初始化程序来引导 CXF servlet:

public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
{
  @Override
  protected void registerContextLoaderListener(ServletContext servletContext)
  {
    CXFServlet cxfServlet = new CXFServlet();
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("cxf", cxfServlet);
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/services/*");
  }

  .....
}

我有一个 Spring 配置类:

@Configuration
public class WebServiceConfiguration
{
  @Bean
  public Endpoint endPoint()
  {
    EndpointImpl endpoint = new EndpointImpl(cxf(), eorthoWebService());
    endpoint.getHandlers().add(inboundRequestHandler());
    endpoint.getHandlers().add(outboundRequestHandler());
    //the below works and uses cxf's embedded Jetty server
    //endpoint.publish("http://localhost:9090/services/EorthoWebService");
    //this doesn't work
    endpoint.publish("/EorthoWebService");

    return endpoint;
  }

  @Bean
  public SpringBus cxf()
  {
    return new SpringBus();
  }

  @Bean
  public EorthoWebService eorthoWebService()
  {
    return new EorthoWebServiceImpl();
  }
}

我有一个 Web 服务实现:

@WebService(endpointInterface = "com.aoa.eortho.ws.service.EorthoWebService")
@SchemaValidation(type = SchemaValidationType.IN)
public class EorthoWebServiceImpl implements EorthoWebService {

    @WebMethod
    public RulesEngineOrthodonticSubmissionResponseEnv processRequest(RulesEngineOrthodonticSubmissionRequestEnv requestEnvelope) {
        ...
    }
}

当我点击 /services 时,我得到输出:

没有找到任何服务。

我可以让它工作的唯一方法是通过如下发布,这似乎将其发布到嵌入式 Jetty 服务器而不是它部署到的 Tomcat 实例:

endpoint.publish("http://localhost:9090/services/EorthoWebService");

为了让它在 Tomcat 上运行,我缺少什么:

endpoint.publish("/EorthoWebService");

您缺少的部分是 spring 上下文扫描。

From Baeldung http://www.baeldung.com/ -- Apache CXF 与 Spring 指南 http://www.baeldung.com/apache-cxf-with-spring

首先,创建并配置 Spring 应用程序上下文以注册包含配置元数据的类:

AnnotationConfigWebApplicationContext context 
    = new AnnotationConfigWebApplicationContext();
context.register(ServiceConfiguration.class);

ServiceConfiguration 类使用 @Configuration 注释来注释以提供 bean 定义。此类将在下一小节中讨论。 以下代码片段显示了如何将 Spring 应用程序上下文添加到 servlet 上下文:

container.addListener(new ContextLoaderListener(context));

所以,完整的类是:

public class AppInitializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext container) {

        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(ServiceConfiguration.class);

        container.addListener(new ContextLoaderListener(context));

        // Register and map the dispatcher servlet
        ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new CXFServlet());
        dispatcher.setLoadOnStartup(1);

        dispatcher.addMapping("/services/*");
    }
}

哪个与你的不同AbstractAnnotationConfigDispatcherServletInitializer扩展类但是当我重写时onStartup代替registerContextLoaderListener它似乎也同样有效。希望这足以让您解决问题。

另外,我的配置类:

@Configuration
public class ServiceConfiguration {

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(cxf(), new HelloWorldImpl());
        endpoint.publish("/HelloWorld");
        return endpoint;
    }

    @Bean
    public SpringBus cxf() {
        return new SpringBus();
    }

}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tomcat下的Spring CXF Soap Web服务:找不到服务 的相关文章

  • Oracle Java 教程 - 回答问题时可能出现错误

    我是 Java 新手 正在阅读 Oracle 教程 每个部分之后都有问题和答案 我不明白一个答案中的一句话 见下面的粗体线 来源是https docs oracle com javase tutorial java javaOO QandE
  • (Java) App Engine 中的静态文件无法访问

    The 示例文档 http code google com appengine docs java gettingstarted staticfiles html表示您只需将文件放在 war 或子目录 中 并且应该可以从主机访问它们 只要它
  • HAProxy SSL终止+客户端证书验证+curl/java客户端

    我希望使用我自己的自签名证书在 HAProxy 上进行 SSL 终止 并使用我创建的客户端证书验证客户端访问 我通过以下方式创建服务器 也是 CA 证书 openssl genrsa out ca key 1024 openssl req
  • 文本在指定长度后分割,但不要使用 grails 打断单词

    我有一个长字符串 需要将其解析为长度不超过 50 个字符的字符串数组 对我来说 棘手的部分是确保正则表达式找到 50 个字符之前的最后一个空格 以便在字符串之间进行彻底的分隔 因为我不希望单词被切断 public List
  • 从 MS Access 中提取 OLE 对象(Word 文档)

    我有一个 Microsoft Access 数据库 其中包含一个包含 Microsoft Word 文档的 OLE 对象字段 我试图找到代码来检索保存在 OLE 对象中的文件 以便用户可以从我的 JavaFx 应用程序中的按钮下载它 但没有
  • 为什么Iterator接口没有add方法

    In IteratorSun 添加了remove 方法来删 除集合中最后访问的元素 为什么没有add方法来向集合中添加新元素 它可能对集合或迭代器产生什么样的副作用 好的 我们开始吧 设计常见问题解答中明确给出了答案 为什么不提供 Iter
  • org/codehaus/plexus/archiver/jar/JarArchiver(不支持的major.minor版本49.0)-Maven构建错误

    下午大家 我在尝试构建项目时收到上述错误 我很确定这与使用 Java 1 6 编译的 Maven 最新更新有关 而我们尝试构建的项目是 1 4 项目 在此之前的插件工作没有问题 因此我将以下内容添加到 POM xml 文件中以尝试强制使用现
  • Spring Batch:一个读取器、多个处理器和写入器

    在 Spring 批处理中 我需要将 ItemReader 读取的项目传递给两个不同的处理器和编写器 我想要实现的是 gt ItemProcessor 1 gt ItemWriter 1 ItemReader gt item gt Item
  • 如何停止执行的 Jar 文件

    这感觉像是一个愚蠢的问题 但我似乎无法弄清楚 当我在 Windows 上运行 jar 文件时 它不会出现在任务管理器进程中 我怎样才能终止它 我已经尝试过 TASKKILL 但它对我也不起作用 On Linux ps ef grep jav
  • JAVA中遍历JSON数据

    我是 JSON 新手 我使用 HTTPUrlConnections 并在 JAVA 程序中获得一些响应 响应数据将类似于 data id 1 userId 1 name ABC modified 2014 12 04 created 201
  • Play.application() 的替代方案是什么

    我是 Play 框架的新手 我想读取conf文件夹中的一个文件 所以我用了Play application classloader getResources Data json nextElement getFile 但我知道 play P
  • Java - 从 XML 文件读取注释

    我必须从 XML 文件中提取注释 我找不到使用 JDOM 或其他东西来让它们使用的方法 目前我使用 Regex 和 FileReader 但我不认为这是正确的方法 您可以使用 JDOM 之类的东西从 XML 文件中获取注释吗 或者它仅限于元
  • 避免 Java 中的重复导入:继承导入?

    有没有办法 继承 导入 Example 常见枚举 public enum Constant ONE TWO THREE 使用此枚举的基类 public class Base protected void register Constant
  • 我可以限制分布式应用程序发出的请求吗?

    我的应用程序发出 Web 服务请求 提供商处理的请求有最大速率 因此我需要限制它们 当应用程序在单个服务器上运行时 我曾经在应用程序级别执行此操作 一个对象跟踪到目前为止已发出的请求数量 并在当前请求超出允许的最大负载时等待 现在 我们正在
  • 如何从 Spring Boot 中排除依赖项

    我正在使用 Spring Boot 以下是我的 gradle 文件 buildscript ext springBootVersion 2 0 0 BUILD SNAPSHOT repositories mavenCentral maven
  • 如何处理 StaleElementReferenceException

    我正在为鼠标悬停工作 我想通过使用 for 循环单击每个链接来测试所有链接的工作条件 在我的程序中 迭代进行一次 而对于下一次迭代 它不起作用并显示 StaleElementReferenceException 如果需要 请修改代码 pub
  • 源值 1.5 的错误已过时,将在未来版本中删除

    我使用 scala maven plugin 来编译包含 scala 和 java 代码的项目 我已经将源和目标设置为1 7 但不知道为什么maven仍然使用1 5 这是我在 pom xml 中的插件
  • 何时在 hibernate 中使用 DiscriminatorValue 注解

    在 hibernate 中使用 DiscriminatorValue 注释的最佳场景是什么以及何时 这两个链接最能帮助我理解继承概念 http docs oracle com javaee 6 tutorial doc bnbqn html
  • Java 的 PriorityQueue 与最小堆有何不同?

    他们为什么命名PriorityQueue如果你不能插入优先级 它看起来与堆非常相似 有什么区别吗 如果没有区别那为什么叫它PriorityQueue而不是堆 默认的PriorityQueue是用Min Heap实现的 即栈顶元素是堆中最小的
  • 检查应用程序是否在 Android Market 上可用

    给定 Android 应用程序 ID 包名称 如何以编程方式检查该应用程序是否在 Android Market 上可用 例如 com rovio angrybirds 可用 而 com random app ibuilt 不可用 我计划从

随机推荐