์ƒˆ์†Œ์‹

Back-End/Spring

[SpringBoot] IntelliJ์—์„œ Springboot + gradle ์‹คํ–‰ํ•˜๊ธฐ

  • -

 

 

 

 

IntelliJ์—์„œ Springboot ์‹คํ–‰ํ•˜๊ธฐ

 

1. ๊ธฐ๋ณธ์„ค์ • ํ™•์ธ ํ›„ Next

 

2. GroupId์™€ ArtifactId ์„ค์ •. ํŠนํžˆ ArtifactId๋Š” ํ”„๋กœ์ ํŠธ์˜ ์ด๋ฆ„์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์›ํ•˜๋Š” ์ด๋ฆ„์œผ๋กœ ์ž‘์„ฑ ํ›„ Finish

 

3. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ

 

4. build.gradle ํŒŒ์ผ์„ ์—ด์–ด ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ ํ›„ ์šฐ์ธก ํ•˜๋‹จ์— Enable Auto-Import ํด๋ฆญ

buildscript {
    ext {
        springBootVersion = '2.1.7.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group 'com.tistory.mincoding'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

 

5. gradle ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋“ฑ๋ก์ด ๋˜์—ˆ๋Š”์ง€ ์•„๋ž˜์™€ ๊ฐ™์ด ํ™•์ธ

 

6. Application.java ์ƒ์„ฑ

package com.tistory.mincoding.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

 

7. TestController.java ์ƒ์„ฑ

package com.tistory.mincoding.springboot.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("test")
    public String test() {
        return "test";
    }

}

 

8. ์•„๋ž˜์™€ ๊ฐ™์ด ์‹คํ–‰(ํ˜น์€ Ctrl + Shift + F10) ํ›„ ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์—ด์–ด localhost:8080/test๋กœ ์ ‘์† ๋ฐ ํ™•์ธ

 

9. ๊ฒฐ๊ณผ ํ™”๋ฉด

 

์ถ”๊ฐ€) ํฌํŠธ๊ฐ€ ์ค‘๋ณต์ด ๋˜์—ˆ์„ ๋•Œ๋Š” application.properties์— ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

src/main/resources ์•ˆ์— config ๋””๋ ‰ํ„ฐ๋ฆฌ ์ƒ์„ฑ ํ›„ application.properties ํŒŒ์ผ ์ƒ์„ฑ

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜Š

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๐Ÿ‘