-
[Spring Boot] Spring Boot (1) - 개발환경 설정JAVA/SPRING 2020. 1. 5. 22:09728x90
1. Eclipse 설치
The Platform for Open Innovation and Collaboration | The Eclipse Foundation
The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
www.eclipse.org
2. 플러그인 설치 (STS, Gradle)
Eclipse Marketplace에서 STS, Gradle 플러그인 설치
3. 프로젝트 생성
File -> New -> Spring Starter Project
4. 정상 실행 테스트
package com.ms.study; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @SpringBootApplication public class BootStudyApplication { public static void main(String[] args) { SpringApplication.run(BootStudyApplication.class, args); } @GetMapping("/") public String home() { return "Hello Spring Boot"; } }
Run As -> Spring Boot App (없으면 Java Application)
5. JSP view 연동
// src/main/rescources/application.properties # MVC View spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp
main 디렉토리 밑에 디렉토리 생성
views 폴더에 test.jsp 생성 후
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html> <html> <head> <meta charset="EUC-KR"> <title>Insert title here</title> </head> <body> <h1>test.jsp</h1> </body> </html>
views와 연동을 확인하기 위한 컨트롤러 생성
package com.ms.study; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class testController { @RequestMapping("/") private String index() { return "test"; } }
(404 error가 발생할 경우)
//build.gradle plugins { id 'org.springframework.boot' version '2.2.2.RELEASE' id 'io.spring.dependency-management' version '1.0.8.RELEASE' id 'java' } group = 'com.ms' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'com.h2database:h2' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } compile('org.apache.tomcat.embed:tomcat-embed-jasper') //추가 compile('javax.servlet:jstl:1.2') //추가 } test { useJUnitPlatform() }
프로젝트 우클릭 Gradle -> Refresh Gradle Project
728x90'JAVA > SPRING' 카테고리의 다른 글
[Spring Boot] Spring Boot (3) - CRUD (0) 2020.01.08 [Spring Boot] Spring Boot (2) - 기본 로직 + MySQL 연동 (0) 2020.01.07 [SPRING] MAPPER 비교연산자 에러(The content of elements must consist of well-formed character data or markup) (0) 2019.08.29 [SPRING] MultipartFile 파일업로드 없을 경우 (1) 2019.08.21 [SPRING] resources 사용법 (0) 2019.08.10