【问题标题】:Spring boot app endpoints with Azure App service使用 Azure 应用服务的 Spring Boot 应用终结点
【发布时间】:2019-09-19 08:37:47
【问题描述】:

我正在尝试将简单的 Spring Boot 应用部署到 Azure 应用服务,但看起来应用无法启动。

我的应用在休息端点上

@RequestMapping("/")
public String index() {
    return "Greetings from Spring Boot!";
}

我尝试使用 azure-webapp-maven-plugin 进行部署,pom 中的配置如下所示

  <plugin>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-webapp-maven-plugin</artifactId>
            <version>1.7.0</version>
            <configuration>
                <schemaVersion>V2</schemaVersion>

                <!-- Web App information -->
                <resourceGroup>${resourceGroup}</resourceGroup>
                <appName>boot-test-app</appName>
                <region>westeurope</region>
                <pricingTier>P1V2</pricingTier>
                <runtime>
                    <os>linux</os>
                    <javaVersion>jre8</javaVersion>
                    <webContainer>tomcat 8.5</webContainer>
                </runtime>
                <appSettings>
                    <property>
                         <name>PORT</name>
                        <value>80</value>
                    </property>
                    <property>
                        <name>JAVA_OPTS</name>
                        <value>-Xmx512m -Xms512m</value>
                    </property>
                </appSettings>
                <deployment>
                    <resources>
                        <resource>
                            <directory>${project.basedir}/target</directory>
                            <!--<targetPath>/home/site/wwwroot/webapps/ROOT/</targetPath>-->
                            <includes>
                                <include>*.war</include>
                            </includes>
                        </resource>
                    </resources>
                </deployment>
            </configuration>
        </plugin>

插件说部署成功,但是当我打开应用程序网页时 - 我收到 404 错误。 如果我使用 Azure Plugin for Intellij Idea 进行部署,情况也是如此。

我错过了什么? 谢谢!

【问题讨论】:

    标签: java spring azure spring-boot


    【解决方案1】:

    请按照本教程部署:Spring Boot on Linux。我测试了多次,这适用。或者你可以使用我的 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>  
      <groupId>org.springframework</groupId>  
      <artifactId>gs-spring-boot</artifactId>  
      <version>0.1.0</version>  
      <parent> 
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-parent</artifactId>  
        <version>2.1.6.RELEASE</version> 
      </parent>  
      <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> 
        </dependency>  
        <!-- end::tests[] --> 
      </dependencies>  
      <properties> 
        <java.version>1.8</java.version> 
      </properties>  
      <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.6.0</version>  
            <configuration>
              <schemaVersion>V2</schemaVersion>
              <resourceGroup>group name</resourceGroup>
              <appName>app name</appName>
              <region>westeurope</region>
              <pricingTier>P1V2</pricingTier>
    
    
              <!-- Begin of App Settings  -->
              <appSettings>
                 <property>
                       <name>JAVA_OPTS</name>
                       <value>-Dserver.port=80</value>
                 </property>
              </appSettings>
    
              <runtime>
                <os>linux</os>
                <javaVersion>jre8</javaVersion>
                <webContainer>jre8</webContainer>
              </runtime>
              <deployment>
                <resources>
                  <resource>
                    <directory>${project.basedir}/target</directory>
                    <includes>
                      <include>*.jar</include>
                    </includes>
                  </resource>
                </resources>
              </deployment>
            </configuration>
          </plugin>  
          <plugin> 
            <artifactId>maven-failsafe-plugin</artifactId>  
            <executions> 
              <execution> 
                <goals> 
                  <goal>integration-test</goal>  
                  <goal>verify</goal> 
                </goals> 
              </execution> 
            </executions> 
          </plugin> 
        </plugins> 
      </build> 
    </project>
    

    部署后,如果网页仍然没有显示正确的页面,请检查运行时堆栈是否与您在 pom.xml 中定义的相同。

    【讨论】:

    • 谢谢,我忘了删除&lt;webContainer&gt; 选项。
    猜你喜欢
    • 2021-02-26
    • 1970-01-01
    • 2018-09-08
    • 2021-11-21
    • 1970-01-01
    • 2021-02-07
    • 2018-05-21
    • 2021-05-18
    • 1970-01-01
    相关资源
    最近更新 更多