2016年11月08日 16:18:21
折腾了差不多一天才搞定,各种异常,到现在不知道这些异常干嘛的,总之是对spring-boot和maven都不熟悉;
JAR包
- idea ->
- run/debug Configurations: + maven
- Command line: package -X spring-boot:repackage
- 其中,-X表示maven构建时用debug模式;
- package在前,spring-boot:repackage在后;
- 添加spring-boot-plugin
WAR包
- pom: ``` <packaging>war</packaging>
* pom :
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
```
* spring-boot-starter-tomcat的作用范围设为provided,仅在测试和调试时起使用;
* pom: 添加plugin,告诉maven构建时不使用web.xml文件
<!-- maven打包的时候告诉maven不需要web.xml,否刚会报找不到web.xml错误 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
***
* 问题: Pom排除tomcat,加上jetty,报错,如下第二行
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:189) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
* 解决:通过spring-boot:run运行;