【问题标题】:Issues Converting Mule Tomcat WAR to Spring Boot将 Mule Tomcat WAR 转换为 Spring Boot 的问题
【发布时间】:2015-09-16 12:26:21
【问题描述】:

我正在经历将我的 Mule 项目转换为 Spring Boot 应用程序的过程,但遇到了一个我似乎无法弄清楚的问题。

我对 Spring Boot 还很陌生,所以我不确定我的问题是出在它上,还是出在我做 mule 的方式上。

这是我一直在尝试转换的示例项目:https://github.com/JustinBell/mule-webapp-example

当我将它部署到 tomcat 实例时,它运行良好,但当我尝试将它作为 Spring Boot 应用程序运行时,我遇到了这个异常:

ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

作为说明,我正在从 mule 3.6.1 迁移到 3.7.0-M1,因为这是使用 Spring Boot 所必需的(根据我的理解)。

我已尝试四处寻找有关此问题的支持,这似乎很常见,但我发现的任何建议都没有解决该问题。

感谢您对这些问题的任何帮助!

【问题讨论】:

  • 我注意到servlet:inbound-endpoint 中的github.com/JustinBell/mule-webapp-example/blob/master/src/main/… :您将使用什么Servlet 容器? Spring boot 是否将 web.xml 加载到 Servlet 容器中?
  • 我的理解是,将使用带有 Spring Boot 的嵌入式 tomcat 实例,但你的问题让我再次思考,所以我正在研究嵌入式实例如何工作以确保它是做我所期望的。

标签: java spring-boot mule


【解决方案1】:

您的代码中有些地方并不完全正确。

如果您想使用 Spring Boot 构建 Web 应用程序,您通常需要添加对 spring-boot-starter-web 的依赖项。这提供了嵌入式 servlet 容器:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>${spring-boot.version}</version>
</dependency>

您的应用程序对 org.mule.transports:mule-transport-servlet 的依赖引入了一个非常旧版本的 Tomcat 的 Coyote 模块。您需要排除它以避免它与spring-boot-starter-web 提供的最新依赖项发生冲突:

<dependency>
    <groupId>org.mule.transports</groupId>
    <artifactId>mule-transport-servlet</artifactId>
    <version>${mule.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>coyote</artifactId>
        </exclusion>
    </exclusions>
</dependency>

您的Application 类正在尝试运行MuleContextInitializer,它也将其声明为一个bean。它应该正在运行Application.class

@SpringBootApplication
public class Application {

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

    // ...
}

您的Application 类也在默认包中。您应该避免使用默认包,因为它会导致 Spring Boot 扫描整个类路径以查找您的应用程序的类和配置。将其移动到自己的包中以防止这种情况发生。

最后,应用程序无法启动,因为它正在寻找一个名为 mule-config.xml 的文件。将 mule-webapp-demo.xml 重命名为 mule-config.xml 可以解决此问题。

【讨论】:

  • 感谢您的深入了解!这似乎解决了所有问题,而且信息量很大。
【解决方案2】:

我相信自动删除是一项企业功能,也许您使用的是 ftp 而不是 ftp-ee。

【讨论】:

  • 有趣,我将把这部分从问题中剔除,以便对此进行一些研究。
猜你喜欢
  • 2018-10-31
  • 2016-02-15
  • 2016-03-18
  • 1970-01-01
  • 2020-06-17
  • 2018-05-18
  • 1970-01-01
  • 2019-05-05
  • 1970-01-01
相关资源
最近更新 更多