220509 Springboot1 - 프로젝트 생성, 실행
Springboot
*스프링부트
- 독립 실행 가능한 스프링 애플리케이션 개발 가능 (tomcat, jetty 내장)
- 통합 Starter를 이용해 maven/gradle로 라이브러리 관리
- Starter를 통한 자동화된 스프링 설정 제공 (수동으로 조정해야 하는 설정도 있긴 함)
- 번거로운 XML 설정을 요구하지 않음
- Spring Actuator 제공 : 애플리케이션의 모니터링, 관리를 위해 사용)
*프로젝트 생성
file - new - project - Spring Starter Project
얘네는 체크하는 것들 라이브러리를 자동으로 설치해준다
DTO 대신 라이브러리로 대체하는 거 - Lombok (나중에 배울 것)
오라클 연동 - oracle driver (DB 연동 시 체크)
템플릿 - Thymeleaf
등등...
---> 환경설정 파일은 pom.xml만 있음
src - main - java : 컨트롤러, 서비스, dao, dto
- resources - static : 공유 폴더 (css, js, images)
- templates : 타임리프 쓸 때 사용
*실행
프로젝트 우클릭 - Run As - Sring Boot App
콘솔창에 뭐가 잘 뜨면 성공
Description:
Web server failed to start. Port 8080 was already in use.
---> 8080 포트를 이미 사용하고 있다는 뜻. (현재 오라클)
main - resources - application.properties에서 server.port=80으로 지정해주면 된다!
*hello world 출력
main - java - com - example - demo - controller - SampleController.java 생성
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SampleController {
@RequestMapping("/")
public String hello() {
return "hello world";
}
}
@RestController : @Controller+@ResposBody (JSON 형태로 객체 데이터 반환)
+) main - resources - application.properties
#port
server.port=80 쓰고 저장
프로젝트 우클릭 - Run As - Sring Boot App 로 프로젝트 실행 후
http://localhost:80 접속 -> 메시지 출력 확인!