πŸ’Š Java & Kotlin & Spring/- spring framework +

[Spring Boot] ν„°λ―Έλ„μ—μ„œ λΉŒλ“œ 툴 (Maven, Gradle)둜 Spring Boot μ‹€ν–‰μ‹œν‚€κΈ°

Wonit 2021. 4. 24. 19:24

μ˜€λŠ˜μ€ ν„°λ―Έλ„μ—μ„œ Springboot Application 을 μ‹€ν–‰μ‹œν‚€λŠ” 방법에 λŒ€ν•΄μ„œ μ•Œμ•„λ³΄λ € ν•œλ‹€.

 

ν˜„μž¬ Microservice Application 을 κ°œλ°œν•˜κΈ° μœ„ν•΄μ„œ 주둜 Eureka와 Gateway λ₯Ό ν•¨κ»˜ λ™μž‘μ‹œν‚€λŠ” 일이 λ§Žμ•„μ‘Œλ‹€.

 

Service Discovery 역할을 μˆ˜ν–‰ν•˜λŠ” Eureka μ„œλ²„λŠ” 단지 μ„œλΉ„μŠ€μ˜ Registry와 Discovery μƒν™©μ—μ„œ μΌœλ†“κ³ λ§Œ μžˆμ–΄μ•Ό ν•˜λŠ” 상황이 자주 λ°œμƒν•˜λŠ”λ°, 둜컬 개발 ν™˜κ²½μ—μ„œ κΈ°λŠ₯ κ°œλ°œμ„ μœ„ν•΄μ„œλŠ” Eureka μ„œλ²„μ™€ Gateway λ₯Ό Intellij μ—μ„œ μΌœλ†“λŠ” 것이 λŒ€λ‹€μˆ˜μ΄λ‹€.

 

ν•˜μ§€λ§Œ Intellij λŠ” λ‹€μ–‘ν•œ κΈ°λŠ₯을 κ°–κ³ μžˆλŠ” 쑰금 무거운 IDE 이기 λ•Œλ¬Έμ— ν•΄λ‹Ή PC의 λ¦¬μ†ŒμŠ€λ₯Ό 많이 λ¨Ήμ–΄ λΆˆνŽΈν•œ 상황이 μ΄λ§Œμ €λ§Œμ΄ μ•„λ‹ˆλ‹€.

 

그럴 λ•Œ λ§Žμ€ ν•΄κ²° 방법이 μ‘΄μž¬ν•˜κ² μ§€λ§Œ λ‚΄κ°€ 자주 μ• μš©ν•˜λŠ” 방법인 λΉŒλ“œ 도ꡬλ₯Ό μ΄μš©ν•œ Application μ‹€ν–‰ 방법을 κ³΅μœ ν•˜λ € ν•œλ‹€.

 

μ€€λΉ„λ¬Ό

쀀비물은 각각에 λ§žλŠ” Spring boot Applicationκ³Ό Gradle ν˜Ήμ€ Maven 이면 λœλ‹€.

 

  • λΉŒλ“œ 도ꡬ
    • Gradle
    • Maven
  • Spring boot application
  • Terminal

homebrew μ„€μΉ˜

μš°μ„  νŒ¨ν‚€μ§€ 관리 μ‹œμŠ€ν…œμΈ homebrew λ₯Ό μ„€μΉ˜ν•΄λ³΄μž.

 

brew 곡식 ν™ˆνŽ˜μ΄μ§€

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Mavenκ³Ό Gradle 을 brew둜 μ„€μΉ˜

λΉŒλ“œ 도ꡬ인 gradleκ³Ό maven은 각자의 springboot application μŠ€νŽ™μ— 맞게 ν•˜λ‚˜λ§Œ μ„€μΉ˜ν•΄λ„ μ’‹λ‹€.

 

maven μ„€μΉ˜

brew install maven

gradle μ„€μΉ˜

brew install gradle

μ„€μΉ˜κ°€ μ™„λ£Œλ˜μ—ˆμœΌλ©΄ gradle -v ν˜Ήμ€ mvn -v 둜 잘 μ„€μΉ˜λ˜μ—ˆλŠ”μ§€ ν™•μΈν•˜μž.

 

Spring Boot Application μƒμ„±ν•˜κΈ°

기쑴에 Spring Boot Application 이 μ€€λΉ„λ˜μ–΄μžˆλŠ” μ‚¬λžŒμ€ ν•΄λ‹Ή ν”„λ‘œμ νŠΈ λ””λ ‰ν† λ¦¬λ‘œ μ΄λ™ν•˜λ©΄ 되고 λ§Œμ•½ μ€€λΉ„λ˜μ–΄ μžˆμ§€ μ•Šλ‹€λ©΄ κ°μžκ°€ μ›ν•˜λŠ” κΈ°λŠ₯을 κ°–λŠ” Spring Boot Projectλ₯Ό μƒμ„±ν•˜μž.

 

Application.java

@SpringBootApplication
public class UserServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(UserServiceApplication.class, args);
    }
}

Controller.java

@RestController
public void Controller {
    @GetMapping("/")
    public String test() {
        return "User μ„œλΉ„μŠ€μ˜ κΈ°λ³Έ λ™μž‘ Port: {" + port +"}";
    }
}

 

Maven 둜 Spring Boot application μ‹€ν–‰ν•˜κΈ°

$ mvn spring-boot:run

 

Gradle 둜 Spring Boot application μ‹€ν–‰ν•˜κΈ°

$ gradle bootRun

그럼 λ‹€μŒκ³Ό 같이 터미널 ν™˜κ²½μ—μ„œ 잘 μ‹€ν–‰λ˜λŠ” 것을 λ³Ό 수 있고 λΈŒλΌμš°μ €μ—μ„œλ„ μ •μƒμ μœΌλ‘œ μ ‘κ·Ό κ°€λŠ₯ν•œ μƒνƒœκ°€ λœλ‹€.