Spring on Azure

Implement the spring project using IntelliJ

After step 2, we have a basic structure of a spring framework project, we will make it say “Hello World” to us by the following steps,

1. Check and modify pom.xml file

At this point, IntelliJ will load and install all the dependencies according to your pom.xml. To run our project as a .war file, we should delete or comment out the code <!--<scope>provided</scope>--> under the ‘spring-boot-starter-tomcat’ dependency in pom.xml by the following steps,

  • Step 1: Open pom.xml.
  • Step 2: Locate to spring-boot-starter-tomcat dependency.
  • Step 3: Delete or comment out the code<!--<scope>provided</scope>--> .

Comment out TOmcat provided

2. Create a Rest Controller

The next thing you may want to do at this point is add a controller to your application to handle servlet requests.

  • Step 1: Create a com.example.helloworld.web package under com.example.helloworld package.
  • Step 2: Create a new java class named as ‘HelloController.java’ under com.example.helloworld.web package.

Comment out Tomcat

3. Modify controller ‘HelloController.java’

Modify ‘HelloController.java’ as follow,

package com.example.helloworld.com.example.helloworld.web;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController{
    @RequestMapping("/hello")
    public String index(){
        return"Hello world! Greetings!";
        }
    }

4. Build and run your application in localhost:8080

At this point, you can run your application simply by selecting Build project(or Ctrl+F9) and then selecting Run ‘HelloworldApplication’.

Run on local host

Then open an explorer and browse to http://localhost:8080/hello and you’ll see the response from the controller and request mapping we just created.

Open your home page


I ran into an issue I have implemented a spring project