How to develop an App with Spring MVC App with Maven in Eclipse

How to develop an App with Spring Boot MVC framework with Maven in Eclipse

This write-up is for Eclipse users who would like to use Spring STS in Eclipse IDE. There are many Spring framework related blogs in the Internet. Even though they all work, they were inconvenient for users who used to do everything in Eclipse IDE. Also, there are many tutorials that use Maven build of Spring framework with web.xml, etc. but STS simplified the process of setting it up so you can spend more time on actual programming.

Install JRE, Eclipse, Maven, Tomcat (or equivalent), etc. and make sure they are working properly.

Enter your own names for: Name (project name), Artifact, Package. War is for webapp. You can use Jar for Java applications.

Then select what is necessary for your own needs in the next screen. If you are following this to build your first app, don’t need to select anything.

Eclipse will download necessary jar files and set up a framework. This is really convenient. Wait for the completion (it takes a few seconds).

Edit pom.xml as necessary. For this tutorial, add a dependency “spring-boot-configuration-processor” in pom.xml dependency tab. This dependency is for the implementation of @ConfigurationProperites (see 6). It is better to use [Add] button if you don’t exactly know the groupID and artifactID.

Run to check if you have correct Tomcat + Eclipse dev set up as below. If not, you have to add the server. I have Tomcat version 8.5.6 but I changed version number because Eclipse only recognizes 8.0.0. To fake the 8.5.6 to 8.0.0, I unzipped catalina.jar (under lib) and edited version file (ServerInfo.properties) and created jar file again with the jar command below:

Open [artifact]Application.java under src/main/java/[package]. In my case, it is under com.keem. KspbApplication.java.

KspbApplication.java:

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

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

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

@RestController

@SpringBootApplication

//same as @Configuration,@EnableAutoConfiguration,@ComponentScan

publicclass KspbApplication {

@RequestMapping(“/”)

String home() {

return “<a href=/hello?name=Sung>Click to see greeting</a>”;

}

publicstaticvoid main(String[] args) {

SpringApplication.run(KspbApplication.class, args);

}

}

Add controller class and its property. [Artifact]Controller.java

(The main goal of this tutorial is to show you how to build STS in Eclipse so I copied the part of the code from The implementation excerpted from https://dzone.com/articles/spring-boot-support-spring/ Spring Boot Support in Spring Tool Suite 3.6.4 posted by P. Humphrey)