Spring Boot Spring Initializer and awsome small simple Web application – check in 5 mins!

You are currently viewing Spring Boot Spring Initializer and awsome small simple Web application – check in 5 mins!
Photo by Anisur Rahman on Unsplash
Share This Post, Help Others, And Earn My Heartfelt Appreciation! :)
4.9
(1127)

In this post I will show you how you can start your adventure with Spring Boot [ Spring Boot Spring Initializer ]. We will create a new project using “Spring Initializer” and implement a simple controller to display “Hello world from web Spring Boot!” in your browser.

Create new project -> Spring Boot Spring Initializer

To create a ready project based on Maven or Gradle, just go to the website Spring Initializer (Spring.io)

Select:

  • Project: Maven
  • Project Metadata Group: com.bigdataetl
  • Project Metadata Artifact: webdemo
  • Dependencies: Spring Web

Then click the Generate button and after a while we will have a ready package of webdemo.zip to download. We download the file, unpack and open it in our favorite IDE, e.g. IntelliJ IDEA. (Spring Boot Spring Initializer)

Spring Boot Spring Initializer and awsome small simple Web application - check in 5 mins!

Module overview

Let’s take a look at the design tree first. Spring Boot has created for us all the necessary directories and classes to be able to start working as soon as possible, and not to create directories.

As we can see in the picture below we have created:

  • Main class: WebdemoApplication.class – we also see annotations @SpringBootApplication
  • The resources directory and in it ready directories for our html page patterns, css or js files. In addition, we see the application.properties file that will be used to parameterize our application.
  • The test catalog with ready test class for our main application.
Spring Boot Spring Initializer and awsome small simple Web application - check in 5 mins!
package com.bigdataetl.webdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WebdemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(WebdemoApplication.class, args);
	}

}

Controller

We will now create a class that will be responsible for handling the request at http://localhost:8080/hello

To do this, create a new com.bigdataetl.controller package and the HelloController.class class inside this package.

package com.bigdataetl.webdemo.controller;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String helloWorldFromSpringBoot() {
        return "Hello World from Spring Boot!";
    }

}

Run the Web application

Now just run our main class or WebdemoApplication.class. In the logs you will see how Spring Boot automatically configured the Apache Tomcat service for you on port 8080.

o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-03-01 22:24:35.845  INFO 8804 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

Now just run the URL in your browser: http://localhost:8080/hello and you’ll see that you get what the helloWorldFromSpringBoot() method returns to us:

    @RequestMapping("/hello")
    public String helloWorldFromSpringBoot() {
        return "Hello World from Spring Boot!";
    }
Spring Boot Spring Initializer and awsome small simple Web application - check in 5 mins!

Below is the full log of the launch:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.5.RELEASE)

2020-03-01 22:24:34.706  INFO 8804 --- [           main] c.bigdataetl.webdemo.WebdemoApplication  : Starting WebdemoApplication on pawel with PID 8804 (/home/pawel/Desktop/Blog/webdemo/target/classes started by pawel in /home/pawel/Desktop/Blog/webdemo)
2020-03-01 22:24:34.713  INFO 8804 --- [           main] c.bigdataetl.webdemo.WebdemoApplication  : No active profile set, falling back to default profiles: default
2020-03-01 22:24:35.832  INFO 8804 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-03-01 22:24:35.845  INFO 8804 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-01 22:24:35.845  INFO 8804 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-01 22:24:35.911  INFO 8804 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-03-01 22:24:35.912  INFO 8804 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1111 ms
2020-03-01 22:24:36.118  INFO 8804 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-01 22:24:36.260  INFO 8804 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-01 22:24:36.265  INFO 8804 --- [           main] c.bigdataetl.webdemo.WebdemoApplication  : Started WebdemoApplication in 2.146 seconds (JVM running for 2.673)
2020-03-01 22:24:37.301  INFO 8804 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-01 22:24:37.302  INFO 8804 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-03-01 22:24:37.313  INFO 8804 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 10 ms

That’s all about Spring Boot Spring Initializer!

If you enjoyed this post please add the comment below and share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!

How useful was this post?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 1127

No votes so far! Be the first to rate this post.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments