首页 > 解决方案 > Java 应用始终部署为 Azure 上的新应用服务

问题描述

我正在尝试通过 Azure Shell 部署 .jar SpringBoot 应用程序。我已经(通过站点)创建了应用服务计划和应用服务,所以在 pom 配置中我提到了现有服务的名称。所以当我试图运行mvn azure-webapp:deploy它总是失败

“同名的服务已经存在”

有没有办法在不创建新 AppService 的情况下强制使用现有 AppService?因为现在看起来它会尝试在我所做的每一次更新中进行创建。

更新:我的工作插件设置

             <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>1.12.0</version>
                <configuration>
                    <schemaVersion>V2</schemaVersion>
                    <resourceGroup>___</resourceGroup>
                    <appName>___</appName>
                    <appServicePlanName>___</appServicePlanName>
                    <pricingTier>F1</pricingTier>
                    <region>eastus</region>
                    <runtime>
                        <os>windows</os>
                        <javaVersion>11</javaVersion>
                        <webContainer>java 11</webContainer>
                    </runtime>
                    <!-- Begin of App Settings  -->
                    <appSettings>
                        <property>
                            <name>JAVA_OPTS</name>
                            <value>-Dserver.port=80 -Djava.net.preferIPv4Stack=true</value>
                        </property>
                    </appSettings>
                    <!-- End of App Settings  -->
                    <deployment>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/target</directory>
                                <includes>
                                    <include>*.jar</include>
                                </includes>
                            </resource>
                        </resources>
                    </deployment>
                </configuration>
            </plugin>

标签: javaazureazure-web-app-service

解决方案


Java Jdk 版本是问题所在。


我有一个现有的 azure app 服务,一个空的 spring boot 应用程序在本地运行良好,从这里下载:git clone https://github.com/spring-guides/gs-spring-boot

在此处输入图像描述

这是部署到现有应用程序服务的pom.xml对我来说效果很好。

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">  
  <modelVersion>4.0.0</modelVersion>  
  <parent> 
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-starter-parent</artifactId>  
    <version>2.3.3.RELEASE</version>  
    <relativePath/>  
    <!-- lookup parent from repository --> 
  </parent>  
  <groupId>com.example</groupId>  
  <artifactId>spring-boot</artifactId>  
  <version>0.0.1-SNAPSHOT</version>  
  <name>spring-boot</name>  
  <description>Demo project for Spring Boot</description>  
  <properties> 
    <java.version>1.8</java.version> 
  </properties>  
  <dependencies> 
    <dependency> 
      <groupId>org.springframework.boot</groupId>  
      <artifactId>spring-boot-starter-web</artifactId> 
    </dependency>  
    <!-- tag::actuator[] -->  
    <dependency> 
      <groupId>org.springframework.boot</groupId>  
      <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency>  
    <!-- end::actuator[] -->  
    <!-- tag::tests[] -->  
    <dependency> 
      <groupId>org.springframework.boot</groupId>  
      <artifactId>spring-boot-starter-test</artifactId>  
      <scope>test</scope>  
      <exclusions> 
        <exclusion> 
          <groupId>org.junit.vintage</groupId>  
          <artifactId>junit-vintage-engine</artifactId> 
        </exclusion> 
      </exclusions> 
    </dependency>  
    <!-- end::tests[] --> 
  </dependencies>  
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin>  
      <plugin> 
        <groupId>com.microsoft.azure</groupId>  
        <artifactId>azure-webapp-maven-plugin</artifactId>  
        <version>1.12.0</version>  
        <configuration> 
          <schemaVersion>v2</schemaVersion>  
          <subscriptionId>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</subscriptionId>  
          <resourceGroup>MyRG</resourceGroup>  
          <appName>dorisspring</appName>  
          <pricingTier>B1</pricingTier>  
          <region>centralus</region>  
          <runtime> 
            <os>Windows</os>  
            <javaVersion>Java 8</javaVersion>  
            <webContainer>Java SE</webContainer> 
          </runtime>  
          <deployment> 
            <resources> 
              <resource> 
                <directory>${project.basedir}/target</directory>  
                <includes> 
                  <include>*.jar</include> 
                </includes> 
              </resource> 
            </resources> 
          </deployment> 
        </configuration> 
      </plugin> 
    </plugins> 
  </build> 
</project>

这是我的命令:

mvn spring-boot:run
mvn clean install #check the "target" folder including jdk created by this command
mvn azure-webapp:config
mvn azure-webapp:deploy

部署成功:

在此处输入图像描述

提示:确保java版本匹配。


推荐阅读