๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ’Š Java & Kotlin & Spring/- spring framework +

[Spring Boot] ํ„ฐ๋ฏธ๋„์—์„œ ๋นŒ๋“œ ํˆด (Maven, Gradle)๋กœ Spring Boot ์‹คํ–‰์‹œํ‚ค๊ธฐ

by Wonit 2021. 4. 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

๊ทธ๋Ÿผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ„ฐ๋ฏธ๋„ ํ™˜๊ฒฝ์—์„œ ์ž˜ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๊ณ  ๋ธŒ๋ผ์šฐ์ €์—์„œ๋„ ์ •์ƒ์ ์œผ๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๊ฐ€ ๋œ๋‹ค.

๋Œ“๊ธ€