Create a Web Application With Spring Boot

 

This guide shows how to create a simple MVC web application using Spring Boot.

Prerequisites:

  • Eclipse IDE (neon release)
  • Maven 4
  • Java 1.8

1. Create maven web project

Open eclipse then create a new maven web project and name it as SpringBootWebJsp.

The structure of the generated projects look like the following:

2. pom.xml

After creating the web project, the first step is to configure Spring Boot inside pom.xml, so we add the following as a parent dependency:

Spring Boot exposes a starter called spring-boot-starter-web which automatically imports all the required jars needed to setup a typical Spring MVC application and automatically configures the view resolver and the servlet dispatcher of the application so that the developer focuses on the development rather than the configuration, so we add the starter as a dependency:

Since we’re using JSP as the front end technology, we need to add the following dependency in order to be able to compile JSP and make use of its features:

That’s all, just 2 dependencies can make your MVC application up. Below are the auto-imported jars:

This is the whole pom.xml for reference:

P.S: when using JSP as a front end technology, you should make sure to set the “packaging” attribute as war not jar, since Spring Boot team claimed that currently there is limitations for supporting JSP inside jar file ( the view resolver wouldn’t map correctly).

3. Application.java

The second step is to create the Spring Boot initializer class, this is the entry point of our application. When annotating a class with @SpringBootApplication, we’re configuring our application to run over the embedded servlet container provided by Spring Boot (tomcat by default).

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

4. application.properties

Spring Boot auto configures the view resolver and the dispatcher servlet of the web application and provides us a way to define our own configuration using application.properties.

So we create application.properties under src/main/resources and define the following properties:

Here we’re configuring the view resolver to map the views to files of type jsp under “WEB-INF/jsp/”. We also change the default port of the embedded tomcat to be 9093, as well as defining other business message properties to be used later on inside our application.

5. home.jsp

In this tutorial, we’re creating a very simple MVC application which displays a welcome message to the end user, so we create a very basic jsp file called home.jsp under WEB-INF/jsp:

 

6. HomeController.java

Now we create our main controller named HomeController under com.programmer.gate and we define it to serve requests coming from the root path as the following:

Our controller simply reads the welcome message from application.properties and then redirects to home.jsp.

7. Deploy the application

Following are the steps to deploy our application:

  • Right click pom.xml -> run-as -> Maven install
  • Maven generates a war file called SpringBootWebJSP-0.0.1-SNAPSHOT.war inside target folder
  • Open cmd, then run the war using: java -jar SpringBootWebJSP-0.0.1-SNAPSHOT.war

Here we go, our application is up and ready to serve requests at port 9093.

That’s it, i hope you like it. For clarifications please leave your thoughts in the comments section below.

 

[출처] http://programmergate.com/spring-boot-jsp/

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
126 Creating a CRUD REST API/Service with Spring Boot, JPA and Hibernate file 졸리운_곰 2018.08.17 147
125 Spring boot에서 REST API 개발 시작해보기 file 졸리운_곰 2018.08.17 350
124 [JSP] 네이버 스마트 에디터 연동 + 이미지파일 업로드 기능 추가 file 졸리운_곰 2018.07.28 1123
123 Use React and Spring Boot to Build a Simple CRUD App file 졸리운_곰 2018.07.28 385
122 JSP CRUD Example jsp 기본예제 file 졸리운_곰 2018.07.28 166
121 스웨거 2.0으로 스프링 부트 어플리케이션 API 문서화하기 file 졸리운_곰 2018.05.24 132
120 Spring REST API 문서를 Swagger로 만들자 file 졸리운_곰 2018.05.22 411
119 Spring REST API에 Swagger 2 설정하기 file 졸리운_곰 2018.05.22 335
118 Spring Boot와 AngualrJS를 조합한 코드 자동 생성 도구(scaffolding) file 졸리운_곰 2018.05.17 141
117 Spring java Code 기반 설정 Configuration 어노테이션과 Bean 어노테이션 졸리운_곰 2018.05.14 77
116 java spring redis 세션 공유 : Spring Session을 이용한 세션 클러스터링 졸리운_곰 2018.05.06 1041
115 Spring MVC hello world example file 졸리운_곰 2018.05.04 223
» Create a Web Application With Spring Boot file 졸리운_곰 2018.05.03 142
113 Spring Boot and JSP Tutorial file 졸리운_곰 2018.05.03 427
112 Spring Boot Hello World Example – JSP file 졸리운_곰 2018.05.03 109
111 Spring Boot – JSP View Example file 졸리운_곰 2018.05.03 137
110 SpringMVC-JSP 프로젝트를 Spring Boot로 옮기기 file 졸리운_곰 2018.05.03 319
109 SPRING BOOT에서 JSP 사용하기 졸리운_곰 2018.05.03 65
108 MYBATIS 기본 - SELECTLIST file 졸리운_곰 2018.03.26 79
107 Spring MVC 에 MyBatis 적용해 보기. file 졸리운_곰 2018.03.26 94
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED