maven 配置eureka服務端多環境

配置文件:html

pom文件:spring

此處需注意:網上不少對maven變量替換的描述都不全,若是要開啓maven變量替換必須將docker

filtering和useDefaultDelimiters同時設置爲true方可生效
<?xml version="1.0" encoding="UTF-8"?>

<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.cyh</groupId>
  <artifactId>ums.eureka.server</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>ums.eureka.server</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  <parent>
      <!--引入spring boot 父項目-->
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.0.RELEASE</version>
  </parent>
  <dependencies>
      <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      </dependency>
  </dependencies>
  <dependencyManagement>
      <dependencies>
          <!--引入spring cloud 依賴管理-->
          <dependency>
              <groupId>org.springframework.cloud</groupId>
              <artifactId>spring-cloud-dependencies</artifactId>
              <version>Finchley.RELEASE</version>
              <type>pom</type>
              <scope>import</scope>
          </dependency>
      </dependencies>
  </dependencyManagement>
  <profiles>
      <profile>
          <id>dev</id>
          <!--激活條件-->
          <activation>
              <!--默認激活-->
              <activeByDefault>true</activeByDefault>
          </activation>
          <properties>
              <profiles.active>dev</profiles.active>
          </properties>

      </profile>
      <profile>
          <id>test</id>
          <properties>
              <profiles.active>test</profiles.active>
          </properties>
      </profile>
      <profile>
          <id>pro</id>
          <properties>
              <profiles.active>pro</profiles.active>
          </properties>
      </profile>
  </profiles>
  
  <build>
    <filters>
        <filter>src/main/resources/application-${profiles.active}.properties</filter>
    </filters>
    <resources>
        <resource>
            <!--打包排除文件-->
            <excludes>
                <exclude>application-dev.properties</exclude>
                <exclude>application-test.properties</exclude>
                <exclude>application-pro.properties</exclude>
            </excludes>
            <directory>src/main/resources</directory>
            <!--打包要複製的文件-->
            <includes>
                <include>application.properties</include>
            </includes>
            <!--開啓變量替換-->
            <filtering>true</filtering>
        </resource>
    </resources>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.1.0</version>
          <configuration>
              <!--開啓變量替換-->
              <useDefaultDelimiters>true</useDefaultDelimiters>
          </configuration>
        </plugin>
          <!--maven運行springboot插件-->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.cyh.App</mainClass>
            </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

運行apache

在此處咱們還能夠將springboot打爲war包,引入tomcat7-maven-plugin插件運行maven命令一鍵部署。tomcat

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <!-- 注意tomcat7此處的url -->
        <url>http://localhost:8080/manager/text</url>
        <server>tomcat7</server> <!-- 此處的名字必須和setting.xml中配置的ID一致-->
        <path>/</path> <!-- 此處的名字是項目發佈的工程名-->
    </configuration>
</plugin>

若是服務器比較多能夠用Jenkins+docker的方式部署springboot

相關文章
相關標籤/搜索