将 Mule Tomcat WAR 转换为 Spring 引导的问题

Issues Converting Mule Tomcat WAR to Spring Boot

我一直在经历将我的 Mule 项目转换为 Spring 引导应用程序的过程,但遇到了一个我似乎无法弄清楚的障碍。

我是 Spring Boot 的新手,所以我不确定我的问题是在于它,还是在于我做 mule 事情的方式。

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

当我将其部署到 tomcat 实例时它运行良好,当我尝试将其 运行 作为 Spring 启动应用程序时出现问题我收到此异常:

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

请注意,我将从 mule 3.6.1 转移到 3.7.0-M1,因为这是使用 Spring Boot 所必需的(根据我的理解)。

我尝试四处寻找关于这个问题的支持,这似乎很常见,但我发现的 none 的建议已经解决了这个问题。

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

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

您的代码中有几处不太正确。

如果您想使用 Spring Boot 构建网络应用程序,您通常需要添加对 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 class 正在尝试 运行 MuleContextInitializer 它也声明为一个 bean。应该是 运行ning Application.class:

@SpringBootApplication
public class Application {

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

    // ...
}

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

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