1. 程式人生 > >spring cloud 打war包釋出到tomcat中

spring cloud 打war包釋出到tomcat中

思路:

 1.serlvet啟動類

 2.spring boot 啟動類

 3.配置pom.xml 檔案

 4.大war包 

 5.啟動tomcat

 6.訪問

重點

  1. servlet啟動類中的DeptProvider8004_App 是springboot 的啟動類 要放到同一層目錄下

  2. 配置pom中的資訊

  3. 訪問地址加上 tomcat埠/sup/服務地址

 

serlvet啟動類

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DeptProvider8004_App.class);
    }
}

springboot啟動類

@SpringBootApplication
public class DeptProvider8004_App {
	public static void main(String[] args) {
		SpringApplication.run(DeptProvider8004_App.class, args);
	}
}

pom.xml檔案

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.jinxin</groupId>
  <artifactId>jxsc</artifactId>
  <version>0.0.1</version>
  <!-- <packaging>jar</packaging> -->
  <packaging>war</packaging>
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
        <relativePath />
    </parent>
    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.7</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.38</version>
        </dependency>
        <dependency> 
            <groupId>com.thoughtworks.xstream</groupId> 
            <artifactId>xstream</artifactId> 
            <version>1.4.9</version> 
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
            </dependencies>
    <build>
    <finalName>jxsc</finalName>  
        <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>                 <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>       
        </plugins>
    </build>
</project>

成功日誌

[INFO] --- maven-war-plugin:2.4:war (default-war) @ super-dept-provide-8004 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [super-dept-provide-8004] in [D:\workspace2018_11_19_LJ\super\super-dept-provide-8004\target\sup]
[INFO] Processing war project
[INFO] Webapp assembled in [7108 msecs]
[INFO] Building war: D:\workspace2018_11_19_LJ\super\super-dept-provide-8004\target\sup.war
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ super-dept-provide-8004 ---
[INFO] Installing D:\workspace2018_11_19_LJ\super\super-dept-provide-8004\target\sup.war to D:\workspace2018_11_17\apache-maven-3.5.3\maven_repository\com\supermap\super-dept-provide-8004\0.0.1-SNAPSHOT\super-dept-provide-8004-0.0.1-SNAPSHOT.war
[INFO] Installing D:\workspace2018_11_19_LJ\super\super-dept-provide-8004\pom.xml to D:\workspace2018_11_17\apache-maven-3.5.3\maven_repository\com\supermap\super-dept-provide-8004\0.0.1-SNAPSHOT\super-dept-provide-8004-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.007 s
[INFO] Finished at: 2018-11-20T12:15:34+08:00
[INFO] ------------------------------------------------------------------------

將打成的sup.war檔案放到tomcat 中

 

 

最後訪問埠是tomcat的埠 並且加上sup.war 的sup路徑

協議://ip:埠/sup/自己使用的服務地址

http://localhost:8081/sup/getStrnew/1ee