在您的代碼中有幾件事情並不完全正確。
如果要使用Spring Boot構建Web應用程序,通常需要在spring-boot-starter-web
上添加依賴項。這提供,除其他事項外,嵌入式servlet容器:在一個很舊的版本Tomcat的狼模塊的上拉org.mule.transports:mule-transport-servlet
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
您的應用程序的依賴。你需要排除是爲了避免它與同時由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
解決了這個問題。
我注意到https://github.com/JustinBell/mule-webapp-example/blob/master/src/main/resources/mule-webapp-demo.xml中的'servlet:inbound-endpoint':什麼是Servlet容器你會用嗎? Spring引導是否在Servlet容器中加載'web.xml'? –
我的理解是有一個嵌入式的Tomcat實例可以使用Spring Boot,但是你的問題使我倍加擔心,所以我正在研究嵌入式實例如何工作以確保它能夠按照我期望的那樣工作。 –