英文:
Why Spring Boot Application is not working after Deployment on Azure Web app
问题
以下是翻译好的部分:
Step 1:
创建了一个返回字符串 "Hello" 的 Spring Boot 应用程序,并在本地测试了该代码,成功运行。
Step 2:
在 Azure 门户上创建了一个 Web 应用,并配置了本地 Git 存储库。
Step 3:
在本地复制了 Git URL,并进行了 Git 克隆。
Step 4:
在 Webapps 文件夹内,我将 WAR 文件放置在其中,并将其重命名为 ROOT.war。
Step 4:
执行了以下命令:
git status
git add .
git commit -m "Test"
git push origin master
Step 4:
转到 Azure 门户,检查了 ROOT 文件夹和 WAR 文件,部署成功。
[点击这里查看截屏][1]
Step 6:
当我访问 URL 时,出现了 404 错误:
[点击这里查看错误图片][2]
控制器的代码片段:
package io.javabrains.springbootstarter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "Hello World RESTful with Spring Boot";
}
}
Spring Boot 启动器的代码片段:
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class, args);
}
}
Pom.xml:
在 Pom.xml 中,通过在 Spring Boot 中运行 Maven 插件(目标:mvn-webapp:config),在最后创建了配置,然后在配置标签中映射了我在 Azure 门户中创建的相同值。目标是检查创建了哪些配置属性。
<?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>io.javabrains.springbootquickstart</groupId>
<artifactId>course-api-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Java Brains Course Api</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<!-- WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency> -->
</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.7.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<resourceGroup>first-azure-application-28minutes</resourceGroup>
<appName>CourseapiTest</appName>
<pricingTier>F1</pricingTier>
<region>South Central US</region>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<runtime>
<os>windows</os>
<javaVersion>jre8</javaVersion>
<webContainer>TOMCAT 9</webContainer>
</runtime>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.war</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.properties:
server.forward-headers-strategy=FRAMEWORK
错误信息:在 Azure 的 "Diagnose" 和 "Errors" 部分中:
[点击这里查看错误图片][3]
[点击这里查看错误图片][4]
[1]: https://i.stack.imgur.com/0kjUh.png
[2]: https://i.stack.imgur.com/9Gf1m.png
[3]: https://i.stack.imgur.com/56Bro.png
[4]: https://i.stack.imgur.com/f690e.png
英文:
Could please anyone help me with 404 Error when I try to access the api Url deployed on azure.Due to admin rights , not able to install azure CLI as if now.So I have followed below steps.
Step 1:
Created Spring boot application that is returning string "Hello" from HelloController and tested the code on local and it was up and running.
Step 2:
Create web app on azure portal and configured local git repository.
Step 3:
On my local,I copied the local git url and made git cloning.
Step 4:
Inside Webapps folder created ,I have placed the war file by renaming it to the ROOT.war
Step 4:
Ran the below command:
git status
git add .
git commit -m"Test"
git push origin master
Step 4:
Went on the azure portal and checked the ROOT folder and War File,it was succesfully deployed.
Click here For the Screenshot
Step 6:
When I hit on the url,I am getting 404 error:
Click here for Error Image
Code Snippet For Controller:
package io.javabrains.springbootstarter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "Hello World RESTful with Spring Boot";
}
}
Code Snippet For Spring Boot Starter:
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class,args);
}
}
Pom.xml:
In Pom.xml, Configuration was created in the very last by running maven plugin(goal:mvn-webapp:config) in spring boot that created the default configuration.I then mapped the same values in configuration tag that I have created in my azure portal.Goal was to just check what configutation properties are created.
<?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>io.javabrains.springbootquickstart</groupId>
<artifactId>course-api-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Java Brains Course Api</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>-->
</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.7.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<resourceGroup>first-azure-application-28minutes</resourceGroup>
<appName>CourseapiTest</appName>
<pricingTier>F1</pricingTier>
<region>South Central US</region>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<runtime>
<os>windows</os>
<javaVersion>jre8</javaVersion>
<webContainer>TOMCAT 9</webContainer>
</runtime>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*.war</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.properties:
server.forward-headers-strategy=FRAMEWORK
Errors: Under Diagonose and Section In Azure:
答案1
得分: 1
部署 Spring Boot 应用到 Azure App Service 时,建议部署 JAR 文件。
我按照 这个教程 进行操作,一切正常。如果你总是看到默认页面,你需要添加一个 web.config 文件。
wwwroot 目录下的文件。
web.config 文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\app.jar"">
</httpPlatform>
</system.webServer>
</configuration>
英文:
To deploy a spring boot app to Azure App Service, it is recommended to deploy jar file.
I followed this tutorials and it works fine. If you always see the default page, you need to add a web.config file.
The files under wwwroot directory.
web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\app.jar&quot;">
</httpPlatform>
</system.webServer>
</configuration>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论