标签:bfd return info 启动 work set request tin XML
实例项目共三个模块:
m1
m2
package
其中package依赖m1和m2,将m1和m2编译生成的jar包一起打成一个war包。
springboot项目打成war包部署到tomcat时需要改变启动方式,否则运行tomcat时war包只会解压,但是加载不了
package的Application.java文件内容:
1 import org.springframework.boot.SpringApplication; 2 import org.springframework.boot.autoconfigure.SpringBootApplication; 3 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 4 import org.springframework.boot.builder.SpringApplicationBuilder; 5 6 7 @SpringBootApplication 8 public class Application extends SpringBootServletInitializer { 9 10 public static void main(String[] args) { 11 12 SpringApplication.run(Application.class, args); 13 } 14 15 @Override 16 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 17 return builder.sources(Application.class); 18 } 19 20 }
package的pom.xml文件内容:
1 <?xml version="1.0"?> 2 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>com.trx.spb</groupId> 7 <artifactId>fnc</artifactId> 8 <version>0.0.1</version> 9 </parent> 10 <artifactId>package</artifactId> 11 <name>package</name> 12 <url>http://maven.apache.org</url> 13 <packaging>war</packaging> 14 <properties> 15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 16 </properties> 17 <dependencies> 18 <dependency> 19 <groupId>org.springframework.boot</groupId> 20 <artifactId>spring-boot-starter-web</artifactId> 21 <!-- 去除tomcat插件引用 --> 22 <exclusions> 23 <exclusion> 24 <groupId>org.springframework.boot</groupId> 25 <artifactId>spring-boot-starter-tomcat</artifactId> 26 </exclusion> 27 </exclusions> 28 </dependency> 29 <!-- 设置tomcatjar包的打包域,使war包运行时不与weblogic冲突 --> 30 <dependency> 31 <groupId>org.springframework.boot</groupId> 32 <artifactId>spring-boot-starter-tomcat</artifactId> 33 <scope>provided</scope> 34 </dependency> 35 <dependency> 36 <groupId>com.trx.fnc</groupId> 37 <artifactId>m1</artifactId> 38 <version>0.0.1</version> 39 </dependency> 40 <dependency> 41 <groupId>com.trx.fnc</groupId> 42 <artifactId>m2</artifactId> 43 <version>0.0.1</version> 44 </dependency> 45 <!-- lombok 实体类get、set等方法自动生成器 --> 46 <dependency> 47 <groupId>org.projectlombok</groupId> 48 <artifactId>lombok</artifactId> 49 <scope>provided</scope> 50 </dependency> 51 </dependencies> 52 53 <build> 54 <plugins> 55 <plugin> 56 <artifactId>maven-war-plugin</artifactId> 57 <version>2.6</version> 58 <configuration> 59 <!--如果想在没有web.xml文件的情况下构建WAR,请设置为false。--> 60 <failOnMissingWebXml>false</failOnMissingWebXml> 61 </configuration> 62 </plugin> 63 </plugins> 64 </build> 65 </project>
package的pom.xml有几项特殊点:
1.去除springboot 内嵌的tomcat模块
2.需要使用 maven-war-plugin插件打包,且将failOnMissingWebXml配置项设置为false,要不然提示项目无web.xml文件的错误。
注:
1、使用maven-war-plugin3.0.0,解决了web.xml不存在无法构建war的问题
2、继续使用maven-war-plugin2.6,添加设置failOnMissingWebXml=false
package生成的war包(假设文件名为package.war)部署到tomcat (版本:8.5)后,访问地址http://localhost:8080/package/@RequestMapping路径。
package项目中application.properties文件中的server.port、server.context-path等配置不再起作用。
链接:https://pan.baidu.com/s/1IaPpRD-0Wjil9PhQhk-wJQ
提取码:00za
标签:bfd return info 启动 work set request tin XML
原文地址:https://www.cnblogs.com/labing/p/12735293.html