Spring Boot Application with JSP

Spring Boot Application is a stand-alone solution of a normal Spring Web Application.

It comes with pre-configured conventions of the spring settings.Hence Spring Boot Application needs little configuration and configurations when there is a specific change. 

Features:

  •  Create Stand alone Spring Applications.
  •  Automatically include Spring configurations/load default configurations.
  •  In Memory Tomcat Web server for standalone server.
  •  Provide Production Ready such as metrics/health checks without even adding any extra code.

Requirements:        JDK1.7+,   Maven 3+ 

Stack        Java. Spring Boot 

Like Every Basic Web Application, the Project structure needs to be proper when configuring in Maven, for a Spring Boot Application.

The above pom.xml needs to have the following SpringBoot and JSP dependencies.

SpringBoot:
org.springframework.boot.spring-boot-starter-web
org.springframework.boot.spring-boot-starter-tomcat

JSTL For JServlet/JSP:
javax.servlet.jstl
org.apache.tomcat.embed.tomcat-embed-jasper

The src folder should have the following three components in project structure for Maven to recognize this as a Web project.

  • main/java to store the java sources
  • main/resources to store the java resources.
  • main/webapp to store the jsp/html or web files.

Java Sources:

A Java class needs to be created for the controller to receive the request and send the response back to the client. Create Stand alone Spring Applications.

SpringBootController.java

For creating a spring boot application in Java, we have to create a Java file where the Spring application needs to be booted.

WebApplication.java

JSP/HTML Web Files:

A new simple JSP file needs to be created inside webapps for displaying the web page. Lets call index.jsp

index.jsp

Now we have inform the Spring Boot application about the JSP files, since Spring Boot application for web follows default Spring MVC configuration.

This properties/xml file needs to be created in src/resources folder which will be understood by the Maven.

application.properties

Clean & Build

Once configured, please execute the following instructions to clean & build the Spring Boot Application.

In the Project root directory, please execute the following command.

Running the Spring Boot Application:

Once it is success, we have to start the spring-boot application with another maven command.

Once Spring Boot Application Started, you will get the logs.., as below, with Port number 8080 where Internal Tomcat server started and running.

Now, once the application started, invoke the URL of JSP, to see the application JSP being invoked from Spring boot server.

Leave a Reply

Your email address will not be published. Required fields are marked *