1. 程式人生 > >SpringbootUnable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFact

SpringbootUnable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFact

本地Eclipse執行Spring boot程式的時候正常,打包放到伺服器上之後執行出現瞭如下異常:
Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing 
EmbeddedServletContainerFactory bean. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:140) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476) at org.springframework
.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:658) at org.springframework.boot.SpringApplication.run(SpringApplication.java:355) at org.springframework.boot
.SpringApplication.run(SpringApplication.java:920) at org.springframework.boot.SpringApplication.run(SpringApplication.java:909) at hu.kumite.Application.main(Application.java:17) Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:190) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:163) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ... 7 more
原因是在pom檔案打包的語句不是用的spring boot打包的外掛:
 <build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<executions>
		           <execution>
			       <goals>
			           <goal>repackage</goal>
			       </goals>
			       <configuration>
			           <classifier>exec</classifier>
			       </configuration>
			    </execution>
		        </executions>
		</plugin>
	</plugins>
		
</build>
這麼寫就對了。