Springboot erp system[2] (자바 개발 189일차)

김경빈·2023년 8월 18일
post-thumbnail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
plugins {
    id 'java'
    id 'org.springframework.boot' version '2.5.4'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
 
group = 'com.beans'
version = '0.0.1-SNAPSHOT'
 
java {
    sourceCompatibility = JavaVersion.VERSION_11
}
 
repositories {
    mavenCentral()
}
 
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtimeOnly 'mysql:mysql-connector-java:8.0.32'
    runtimeOnly 'com.h2database:h2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
 
bootJar {
    enabled = true
}
 
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}
tasks.withType(JavaExec) {
    maxHeapSize = "1024m" // 메모리 크기 조절
}
 
dependencyManagement {
    imports {
        mavenBom "org.springframework.boot:spring-boot-dependencies:2.5.4"
    }
}
 
cs

build.gradle의 설정을 하였습니다.


오늘 공부해볼 주제는

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.beans.erp;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class BeansErpApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(BeansErpApplication.class, args);
    }
 
}
 
cs

@SpringBootApplication

입니다.

@SpringBootApplication은 Spring Boot 애플리케이션을 생성하고 구성하는 데 필요한 여러 가지 애노테이션을 하나로 묶어주는 편리한 애노테이션입니다. 이 애노테이션은 Spring Boot 프로젝트에서 주요한 역할을 수행하며, 애플리케이션의 설정과 기본 동작을 지정하는데 사용됩니다.

이 애노테이션은 실제로 세 가지 애노테이션을 함께 묶어놓은 것입니다. 각각의 애노테이션들이 하는 역할을 살펴보겠습니다.

@Configuration: 이 애노테이션은 클래스를 스프링 컨텍스트의 설정 클래스로 지정합니다. 스프링 컨텍스트는 애플리케이션의 빈(bean) 등록과 관리를 담당하는 중요한 역할을 합니다.

@EnableAutoConfiguration: Spring Boot의 자동 구성 기능을 활성화시킵니다. 이 애노테이션은 클래스패스에 있는 클래스들을 스캔하여 자동으로 설정을 추가하고, 프로젝트에 맞게 애플리케이션을 설정합니다.

@ComponentScan: 클래스의 패키지와 하위 패키지를 스캔하여 스프링 빈을 찾아 등록합니다. 스프링 컨텍스트가 어떤 클래스를 빈으로 등록해야 하는지를 알려줍니다.

@SpringBootApplication은 위 세 가지 애노테이션을 포함하고 있으므로, 이 하나의 애노테이션만 추가하면 위 세 가지 역할을 동시에 수행할 수 있습니다. 따라서 Spring Boot 프로젝트에서는 애플리케이션의 설정, 자동 구성, 빈 스캔 등의 중요한 부분을 한 번에 관리할 수 있게 됩니다.

즉, @SpringBootApplication 애노테이션을 사용하면 Spring Boot 애플리케이션을 만들기 위한 필수적인 설정들을 편리하게 제공받을 수 있습니다. 이렇게 한 번에 애노테이션을 사용하여 여러 가지 설정을 관리할 수 있기 때문에, 더 간단하고 빠르게 Spring Boot 프로젝트를 시작할 수 있습니다.

profile
매일매일 무한한 근성으로 코드를 작성합니다.

1개의 댓글

comment-user-thumbnail
2023년 8월 18일

좋은 글 감사합니다.

답글 달기