우당탕탕 개발일지

83일차_Spring Boot 본문

비트캠프/이론 및 정리

83일차_Spring Boot

ujin302 2024. 11. 4. 20:12
반응형

Spring Boot
     
Spring Boot ?
- 스프링 프레임워크의 서브 프로젝트로 만들어졌다.
스프링 부트는 스프링 프레임워크를 사용 가능한 상태로 만들어주는 도구 정도로 이해할 수 있다.
- 스프링 부트는 다른 프레임워크처럼 커맨드 도구를 제공하고 톰캣이나 제티 같은 내장 서버를 통해 
  복잡한 설정과 실행을 간소화했다.
     
스프링 부트 퀵스타트
     
스프링 부트로 프로젝트를 생성하면 스프링을 비롯한 어떤 라이브러리도 개발자가 신경 쓸 필요가 없다. 스프링 부트가 모든 라이브러리를 자동으로 다운로드하고 관리해준다. 스프링 컨테이너를 위한 XML 환경설정 파일 역시 작성하지 않는데, 이는 스프링 부트가 기본적으로 모든 빈(Bean) 설정을 XML이 아닌 어노테이션으로 처리하기 때문이다.
     
생성되는 프로젝트를 웹 프로젝트로 패키징하여 실행하려면 WAR로 설정해야 하지만 스프링 부트는 웹 애플리케이션도 JAR 파일로 패키징하여 실행할 수 있다.

 

 

1. Maven

1. Spring Boot 프로젝트 생성

 

Spring Boot 버전: 3.3.5

 

프로젝트명: chapter01hellomaven

 

jdk: 17

 

 

2. Spring Boot 프로젝트 뜯어보기 & 실행

Spring Boot로 부터 만든 애플리케이션 시작 클래스임을 의미

 

Run 혹은 ctrl+f5 로 실행

 

 

 

2. Gradle

이 이후에는 1번과 동일함.

 

 

 

 

@RestController

 

 

@ComponentScan(basePackages = {"com.example.chapter01hellogradle", "board.controller"})

 

 

3. Spring Boot + React 연동

 

 

 

1. Spring Boot 프로젝트의 build.gradle 파일 설정

2. React 프로젝트 포트 번호 설정

 

 

 

1. Spring Boot 프로젝트

build.gradle 파일 설정

 

Spring Boot 프로젝트 run 할 때마다, 새로운 React 프로젝트의 build 폴더를 Spring Boot 프론트 부분에 붙여 넣음.

 

def frontendDir = "$projectDir/src/main/react01"

sourceSets {
	main {
		resources {
			srcDirs = ["$projectDir/src/main/resources"]
		}
	}
}

processResources {
	dependsOn "copyReactBuildFiles"
}

task buildReact(type: Exec) {
	dependsOn "installReact"
	workingDir "$frontendDir"
	inputs.dir "$frontendDir"
	group = BasePlugin.BUILD_GROUP
	if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
		commandLine "npm.cmd", "run-script", "build"
	} else {
		commandLine "npm", "run-script", "build"
	}
}

task installReact(type: Exec) {
	workingDir "$frontendDir"
	inputs.dir "$frontendDir"
	group = BasePlugin.BUILD_GROUP
	if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
		commandLine "npm.cmd", "audit", "fix"
		commandLine 'npm.cmd', 'install'
	} else {
		commandLine "npm", "audit", "fix"
		commandLine 'npm', 'install'
	}
}

task copyReactBuildFiles(type: Copy) {
	dependsOn "buildReact"
	from "$frontendDir/build"
	into "$projectDir/src/main/resources/static"
}

 

 

2. React

리액트 프로젝트는 Spring Boot와 동일한 Port 번호를 봐라보게 함.

* Spring Boot 기본 포트는 8080이나, 9000으로 재설정함. 

 

반응형

'비트캠프 > 이론 및 정리' 카테고리의 다른 글

88일차_JPA  (0) 2024.11.11
84일차_Thymeleaf (1)  (1) 2024.11.05
82일차_day09  (0) 2024.11.01
81일차_day08: Redux  (0) 2024.10.31
80일차_Spring + React + MyBatis(MySQL)  (0) 2024.10.30