5

I cannot get my Spring Boot site to respond on an Azure Web Instance. I've followed the Java app instructions and the upload instructions. It appears that the IIS server is receiving the request, but the servlet in the war is not responding. According to the documentation, there are a couple of gotchas. In particular, the web.config should be deployed to wwwroot and specify the java path as well as the forwarding port. I believe I've covered these bases -- my web.config is pasted below.

I did try deploying a tomcat server from the marketplace, and that worked fine. When I substitute my war file and web.config, the spring boot app does not work.

One interesting piece of information is that the HTTP_PLATFORM_PORT environment variable does not appear to be defined.

App Settings:

app settings

Azure Console Info (Env variables and Web.config):

D:\home\site\wwwroot

> dir
D:\home\site\wwwroot
Volume in drive D is Windows
 Volume Serial Number is 789E-197B

 Directory of D:\home\site\wwwroot

03/01/2016  02:14 AM    <DIR>          .
03/01/2016  02:14 AM    <DIR>          ..
02/29/2016  08:15 PM    <DIR>          bin
03/01/2016  01:49 AM         8,771,899 web-0.0.1-SNAPSHOT.war
03/01/2016  02:10 AM               496 web.config
03/01/2016  02:08 AM               496 web.custom.config
03/01/2016  01:54 AM             4,868 web.tomcat.config
03/01/2016  02:14 AM    <DIR>          webapps



> echo %java_home%
D:\home\site\wwwroot
D:\Program Files\Java\jdk1.8.0_60


> echo %http_platform_port%
D:\home\site\wwwroot
%http_platform_port%


> cat web.config
D:\home\site\wwwroot
<?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\web-0.0.1-SNAPSHOT.war&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>
Brett
  • 8,575
  • 5
  • 38
  • 51
  • Hi, sorry but could you help me here ? , I uploaded a jar file to /webapp folder but nothing has changed .. do i miss a part ? and where can i find this web.config file ?? thanks in advance ! – SeleM Apr 11 '16 at 14:29
  • 1
    The correct path is site/wwwroot. Use the ftp credentials configured from the Web App in the Azure Portal. The web.config is explained here: https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/ My web.config is essentially identical to the one in the springboot app shown on that page. What happens is that you fire up a custom Http Module that runs your jar. – Brett Apr 11 '16 at 15:00
  • Thanks a lot !! one other question, i dont get the part of firing up a custom Http module , I'm newbie to Azure and those stuffs , and BTW i have also a SpringBoot App .. Sorry for spamming you with comments :( – SeleM Apr 11 '16 at 15:38
  • I uploaded the jar file to the /wwwroot , fixed the `web.config` into the same folder , restarted the `web app` from azure portal and then when i tried to access the site it keeps loading and sometimes it gave me the error 503.. is there any Tomcat configuration ? .. i dont get it .. or do i have to switch to `.war`... sorry again but i'm stuck there! – SeleM Apr 11 '16 at 15:59
  • 1
    That experience is what led me to write this question. In my case, I deployed a "thin jar". If you are using gradle, you must build the java app with 'gradle build' *not* 'gradle jar'. You need a jar with all the dependencies. – Brett Apr 11 '16 at 16:17
  • I'm using maven, I think the `mvn package` command did it with its dependencies, :ç – SeleM Apr 11 '16 at 16:45
  • What do you mean by "you fire up a custom Http Module that runs your jar" maybe the solution resides here ? – SeleM Apr 11 '16 at 16:54
  • Very likely something is wrong with your jar. Try asking a separate question, referencing this one and post your gradle file. Java apps and .Net Core apps run via the httpPlatformhandler, which means that IIS runs as a proxy to your tomcat / NodeJS / DNX application. See: https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/ – Brett Apr 11 '16 at 17:38
  • Thank you very much indeed for your swift replays , it was the java version causing the problem , i switched it from 8 to 7 and it works , even very slowly but it works ! Thanks.. – SeleM Apr 11 '16 at 21:44

4 Answers4

5

Shouldn't that be an executable JAR instead of a WAR? You can run a Spring Boot JAR with just JDK 8 installed, but you need a Java EE app server to deploy a WAR to.

I don't know what the web.config file is; I use Cloud Foundry. All I need is a JAR, a .yml file for configuration, and a JDK. The Spring Boot JAR should have the entire application and its dependencies inside. I use Maven to create the fat JAR.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • The "fat jar" is the key. "gradle build" does the trick. Gradle commands that do not work: "gradle jar" and "gradle war". Thanks again. – Brett Mar 01 '16 at 14:44
  • In https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/#springboot you have the web.config and instructions on how to deploy it. @duffymo maybe you want to add it to your answer. – PhoneixS Apr 21 '16 at 08:01
  • That's not my answer. Add your own. I don't use Azure. – duffymo Apr 21 '16 at 10:54
3

My 2cents, hopefully this can help someone not loose a few hours of their life. I was trying to deploy a spring boot REST service to Azure API App instance and did so through the Kudo interface.

I was deploying a WAR file to an API App service. The API App service was created using the Azure portal and all Application settings were left as their defaults. Other than setting the Java version and web container, no other settings were changed.

enter image description here

I compiled a War file from a maven project in eclipse then renamed the war file to ROOT.war. Using the Kudo console, I dropped the war file under the webapps folder. Note, that I removed the contents of the /webapps/ROOT/ folder. I did not have to add a web.config file. I dragged the war file and uploaded it. But, if you drag it over the 'blue box' it will unzip the war file and this caused the service to fail.

enter image description here

If you drop the war file somewhere other than the blue box, the file is not unzipped.

enter image description here

I then restarted the service, waited a minute, than then was able to access it via the Azure url.

BgRva
  • 1,521
  • 12
  • 26
  • just curious, how do you set the `server.port` in spring boot properties or does it not matter? – Abhishek Dujari Apr 30 '17 at 14:55
  • 1
    in the application.properties file: server.port=PORT_NUMBER – BgRva May 01 '17 at 17:08
  • thanks for coming back and replying :) I am surprised that there was no mention of this environment variable in the azure docs. I actually forced it to 8080 and seemed to work. I am ofcourse wrong to hard code like that. You answer gave me the idea that I am on the right track and with your help I was able to get the `war` format working already. – Abhishek Dujari May 02 '17 at 14:59
0

Per my experience, the simple way for deploying the Spring Boot application on Azure is create a webapp include tomcat and refer to the spring offical doc How to create a deployable war file to create a war file, then deploy it into the path wwwroot\webapps via FTP or Kudu Console.

If you have a existing Spring Boot Jar Application, you can refer to the other spring doc Converting a Spring Boot JAR Application to a WAR to convert the jar file to a war file, then deploy it on Azure WebApp simply.

Your case is vary similar with the SO thread Spring Boot War deployed to Tomcat.

Community
  • 1
  • 1
Peter Pan
  • 23,476
  • 4
  • 25
  • 43
0

Make sure you have the ServletInitializer class in your project.

If it doesn't exist, you can add the class.

public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(YourMainApplication.class);
}

}

Bacar Pereira
  • 1,025
  • 13
  • 18