-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[21기_서채연] spring tutorial 미션 제출합니다. #14
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/gradlew text eol=lf | ||
*.bat text eol=crlf | ||
*.jar binary |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
*# | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.jar | ||
*.sw? | ||
*~ | ||
.#* | ||
.*.md.html | ||
.DS_Store | ||
.attach_pid* | ||
.classpath | ||
.factorypath | ||
.gradle | ||
.metadata | ||
.project | ||
.recommenders | ||
.settings | ||
.springBeans | ||
.vscode | ||
/code | ||
MANIFEST.MF | ||
_site/ | ||
activemq-data | ||
bin | ||
build | ||
!/**/src/**/bin | ||
!/**/src/**/build | ||
build.log | ||
dependency-reduced-pom.xml | ||
dump.rdb | ||
interpolated*.xml | ||
lib/ | ||
manifest.yml | ||
out | ||
overridedb.* | ||
target | ||
.flattened-pom.xml | ||
secrets.yml | ||
.gradletasknamecache | ||
.sts4-cache | ||
|
||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Read Me First | ||
The following was discovered as part of building this project: | ||
|
||
* The original package name 'com.ceos21.spring-boot' is invalid and this project uses 'com.ceos21.spring_boot' instead. | ||
|
||
# Getting Started | ||
|
||
### Reference Documentation | ||
For further reference, please consider the following sections: | ||
|
||
* [Official Gradle documentation](https://docs.gradle.org) | ||
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.3/gradle-plugin) | ||
* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.3/gradle-plugin/packaging-oci-image.html) | ||
* [Spring Web](https://docs.spring.io/spring-boot/3.4.3/reference/web/servlet.html) | ||
|
||
### Guides | ||
The following guides illustrate how to use some features concretely: | ||
|
||
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) | ||
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) | ||
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) | ||
|
||
### Additional Links | ||
These additional references should also help you: | ||
|
||
* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,129 @@ | ||
# spring-tutorial-21st | ||
CEOS back-end 21st spring tutorial project | ||
# 💙1주차 미션 | ||
<span style="color: yellowgreen">*추가 조사</span> <br> | ||
<span style="color: orange">*추가 질문</span> | ||
|
||
## 📜요약 | ||
**Spring** : 자바 엔터프라이즈 개발을 편하게 해주는 오픈소스 경량급 애플리케이션 프레임워크 <br> | ||
**Spring의 특징** : 자바 객체를 직접 스프링 안에서 관리, 객체의 생명 주기를 관리, <span style="color: yellowgreen">*스프링 컨테이너</span>에서 필요한 객체를 가져와 사용 <br> | ||
**POJO** : Getter, Setter로 구성된 가장 순수한 형태의 기본 클래스, 객체지향적인 원리에 충실하면서, 특정 프레임워크나 라이브러리의 특정 기능에 종속되지 않고, 필요에 따라 재활용될 수 있는 방식으로 설계된 오브젝트 <br> | ||
**스프링 삼각형** : POJO는 IoC/DI, AOP, PSA를 통해서 달성 | ||
- AOP : 관점 지향 프로그래밍, 로직의 주입 | ||
- IoC/DI : 객체의 생성과 의존성 관리를 스프링 컨테이너가 수행 | ||
- PSA : 다양한 기술을 일관된 방식으로 사용할 수 있도록 하는 서비스 추상화 (어댑터 패턴 적용) | ||
|
||
**의존성** : 전체는 부분에 의존한다. <br> | ||
의존성 주입을 통해 결합도를 낮춘다. <br> | ||
의존성 주입 방법에는 `=생성자 주입`, `setter 주입`, `필드 주입` 3가지가 있다. <br> | ||
<span style="color: orange">*그럼 셋 중에서 어떤 방법이 가장 대중적/효율적인가?</span> | ||
|
||
|
||
## 💚추가 조사 | ||
### 🔷스프링 컨테이너(Spring Container) | ||
#### 🔹개념 | ||
스프링 컨테이너는 자바 객체의 생명 주기를 관리, 생성된 자바 객체들에게 추가적인 기능을 제공 | ||
|
||
즉, 스프링 컨테이너는 내부에 존재하는 빈의 생명주기를 관리(빈의 생성, 관리, 제거 등)하며, 생성된 빈에게 추가적인 기능을 제공하는 것. | ||
|
||
#### 🔹종류 | ||
`Beanfactory`와 `ApplicationContext` 두 종류의 인터페이스로 구현 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BeanFactory는 빈을 생성하고 관계를 설정하는 IoC의 기본 기능에 초점을 맞춘 것이고, ApplicationContext는 별도의 정보를 참고해서 빈의 생성, 관계 설정 등의 제어를 총괄하는 것에 초점을 맞춘 것이라고 이해하면 되겠네요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 저도 그렇게 이해했습니다! |
||
|
||
(1)`BeanFactory` | ||
- 스프링 컨테이너의 최상위 인터페이스 | ||
- 빈을 등록, 생성, 조회 등 빈을 관리하는 역할 | ||
|
||
(2)`ApplicationContext` | ||
- BeanFactory의 기능을 상속받으므로, 빈을 관리하고 검색하는 기능 뿐만 아니라 그 외 부가 기능을 제공함 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 부가 기능 4개는 각각 어떤 기능인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
4가지 입니다! |
||
|
||
|
||
#### 🔹BeanFactory VS ApplicaionContext | ||
`ApplicaitonContext`가 `BeanFactory`의 기능을 물려 받아 빈을 관리하는 기능은 같다. 그러나 `ApplicationContext`가 더 많은 부가적인 기능을 가지고 있다. | ||
또한 빈 관리의 기능에서도 `BeanFactory`는 처음으로 getBean() 메소드가 호출된 시점에서 해당 빈을 생성하고, | ||
`ApplicationContext`는 Context 초기화 시점에 모든 싱글톤 빈을 미리 로드한 후 애플리케이션 가동 후에는 빈을 지연없이 받을 수 있다. | ||
|
||
따라서 주로 개발에서는 `ApplicationContext`을 주로 사용한다. | ||
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BeanFactory는 Lazy-loading 방식이기에 빈 로딩을 요청 받는 시점에 인스턴스를 만들고 로딩을 하고 ApplicationContext는 pre-loading 방식이군요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에 대해서 조금 더 깊게 고민해봐야할 것 같습니다..!ㅠㅠ
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스프링 빈 링크를 참고하면 BeanFactory와 ApplicationContext의 관계를 구조적으로도 이해하기 좋을 것 같습니다 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 남겨주신 링크에 설명이 꼼꼼히 되어있는 것 같습니다ㅎㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 분들께서도 많은 의견을 주셨지만 저도 궁금해서 하나의 의견을 추가합니다! 주로 개발에서는 applicationContext를 사용한다고 하셨는데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀대로 한번 찾아보면 학습에 더 도움이 될 것 같네요 ㅎㅎ |
||
|
||
#### 🔗참고 자료 | ||
- [[Spring] 스프링 컨테이너(Spring Container)란 무엇인가?](https://ittrue.tistory.com/220) | ||
- [[Spring] 스프링 컨테이너와 빈이란?](https://steady-coding.tistory.com/459) | ||
|
||
<br> | ||
|
||
### 🔷빈(Bean)의 개념과 라이프 사이클 | ||
#### 🔹빈(Bean) 개념 | ||
스프링 컨테이너가 관리하는 자바 객체를 빈(Bean)이라고 한다. | ||
|
||
#### 🔹Bean Life Cycle 프로세스 | ||
1. 스프링 컨테이너 생성 | ||
2. 스프링 빈 인스턴스 생성 | ||
3. 의존성 주입 | ||
4. 초기화 콜백 : 빈이 생성되고, 빈의 의존관계 주입이 완료된 후 호출 | ||
5. 사용 | ||
6. 소멸전 콜백 : 빈이 소멸되기 직전 호출 | ||
Comment on lines
+57
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성자 주입을 한다면 빈 생성부터 의존관계 주입, 초기화 콜백까지 동시에 진행가능해 라이프 사이클을 압축시킬 수 있을 거 같은데 왜 그러지 않는걸까요? 각 단계의 무게와 책임에 대해서도 한번 생각해보면 좋을 거 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 각 단계의 동작 이유?에 대해서 더 조사가 필요할 것 같습니다! |
||
7. 스프링 종료 | ||
|
||
#### 🔗참고 자료 | ||
- [Bean Life Cycle](https://dodokwon.tistory.com/57) | ||
|
||
<br> | ||
|
||
|
||
### 🔷어노테이션(Annotation)의 개념과 동작 원리 | ||
#### 🔹개념 | ||
코드에 메타데이터(추가 정보)를 제공하는 기능. | ||
|
||
#### 🔹동작 원리 | ||
어노테이션은 `리플렉션(Reflection)`을 활용해서 동작한다. | ||
즉, 런타임(실행 중)에 클래스나 메서드의 정보를 읽어와서 특정 로직을 수행한다. <br> | ||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어노테이션을 커스텀할 수 있다는 것도 아셨나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자료조사하면서 커스텀 어노테이션을 봤습니다ㅎㅎ 다른 어노테이션을 이해하는데 확실히 좋겠네요! |
||
|
||
### 🔷스프링에서 어노테이션을 통한 Bean 등록 과정 | ||
스프링은 `컴포넌트 스캔(Component Scan)`과정을 통해 빈으로 등록한다. <br> | ||
<span style="color: yellowgreen">*컴포넌트 스캔 : 스프링 빈으로 등록될 클래스패스를 스캔하여 빈으로 등록하는 과정</span> <br> | ||
1. 설정정보 클래스에 `@ComponentScan` 어노테이션을 추가해준다. | ||
2. 스프링 빈으로 등록할 클래스에 `@Component` 어노테이션을 추가하여 @ComponentScan의 대상이 되도록 지정하고 스프링 빈으로 등록해준다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @component외에 @componentscan의 대상이 되는 어노테이션들이 있을까요? 이들은 왜 스캔의 대상이 될까요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @service, @controller 역시 스캔의 대상이됩니다. 모두 @component를 메타 어노테이션으로 포함하고 있기 때문입니다 |
||
3. 스프링 빈으로 등록할 때 필요한 DI는 `@Autowired`를 이용해 처리한다. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어노테이션의 종류도 다양한 것으로 보였는데, 어떤 종류가 있는지도 알아보신다면 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자주 쓰이는 어노테이션들을 미리 정리해두면 좋을 것 같아요ㅎㅎ |
||
<br> | ||
|
||
### 🔷단위 테스트와 통합 테스트 | ||
#### 🔹개념 및 특징 | ||
(1) `단위 테스트` | ||
- 개념 : 하나의 작은 단위(메서드/클래스)를 독립적으로 테스트 | ||
- 특징 : 빠르게 실행되고 개발 초기 단계에서 버그를 발견하고 수정하는데 효과적 | ||
|
||
(2) `통합 테스트` | ||
- 개념 : 두 개 이상의 단위가 함께 정상적으로 동작하는지 테스트 | ||
- 특징 : 단위 테스트보다 실행시간이 더 길고 복잡하다. 개발자는 시스템의 전체적인 동작을 검증할 수 있다. | ||
|
||
#### 🔹차이점 | ||
| 구분 | 단위 테스트 | 통합 테스트 | | ||
|:-------------:|:-------------:|:------------------------:| | ||
| 목적 | 개별 모듈의 정확성 검증 | 여러 모듈이 정상적으로 함께 동작하는지 검증 | | ||
| 실행 속도 | 빠름 | 느림 | | ||
| 문제 발생 시 원인 파악 | 쉬움 | 어려움 | | ||
|
||
#### 🔹결론 | ||
단위 테스트를 통해 개별 기능을 검증하고, 통합 테스트로 전체적인 흐름을 체크한다. | ||
|
||
#### 🔗참고 자료 | ||
- [단위 테스트와 통합 테스트의 차이점](https://f-lab.kr/insight/unit-vs-integration-test) | ||
|
||
<hr> | ||
|
||
## 🧡추가 질문 | ||
### 🤔그럼 셋 중에서 어떤 방법이 가장 대중적/효율적인가? | ||
**✅ 스프링에서는 `생성자 주입` 방식을 권장한다** | ||
|
||
#### 🔹생성자 주입의 장점 | ||
1. 객체의 불변성 확보 | ||
- 실제 개발에서 의존 관계의 변경이 필요한 상황이 거의 없다. | ||
- 생성자 주입을 통해 변경의 간으성을 배제하고 불변성을 보장하는 것이 좋다. | ||
2. 순환 참조 문제 방지 가능 | ||
- 생성자 주입은 애플리케이션 구동 시점, 객체의 생성 시점에 에러가 발생한다. | ||
3. 테스트 용이 | ||
- 단위 테스트를 진행할 때 순수 자바 코드로 테스트가 가능하다. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우선 1주차 과제 정말 고생하셨습니다 👍
|
||
#### 🔗참고 자료 | ||
- [[Spring] 다양한 의존성 주입 방법과 생성자 주입을 사용해야 하는 이유](https://mangkyu.tistory.com/125) | ||
|
||
## 🏆성공 | ||
 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '3.2.9' | ||
id 'io.spring.dependency-management' version '1.1.7' | ||
} | ||
|
||
group = 'com.ceos21' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
runtimeOnly 'com.h2database:h2' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[33mcommit 6f5c39a1af9ff97223780080d88cb76ba55cfd53[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mmaster[m[33m)[m | ||
Author: 서채연 <[email protected]> | ||
Date: Sat Mar 15 20:52:45 2025 +0900 | ||
|
||
week 1 | ||
|
||
[33mcommit 749e652fb1b931d95220118e8df98f8c189a7a9d[m[33m ([m[1;31morigin/yeonee911[m[33m, [m[1;31morigin/wlqgkrry[m[33m, [m[1;31morigin/mirupio[m[33m, [m[1;31morigin/master[m[33m, [m[1;31morigin/limdodod[m[33m, [m[1;31morigin/leerura[m[33m, [m[1;31morigin/hyesuhan[m[33m, [m[1;31morigin/challonsy[m[33m, [m[1;31morigin/WithFortuna[m[33m, [m[1;31morigin/SeoyeonPark1223[m[33m, [m[1;31morigin/HEAD[m[33m, [m[1;31morigin/Gothax[m[33m, [m[1;32myeonee911[m[33m)[m | ||
Author: limgahyun <[email protected]> | ||
Date: Fri Mar 7 13:46:35 2025 +0900 | ||
|
||
Update README.md | ||
|
||
[33mcommit 41f542373cec9dbc0526f2cc9e87a309fcc81bed[m | ||
Author: limgahyun <[email protected]> | ||
Date: Fri Mar 7 13:45:41 2025 +0900 | ||
|
||
Initial commit |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스프링 삼각형의 구성 요소(IoC/DI, AOP, PSA)간
어떤 관계성이 있어서 삼각형으로 묶였는지의 정보도 추가해주시면 좋을 것 같습니다. : ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인 결과,
세 요소가 유기적으로 결합하여 삼가갛여으로 표현하는 것을 알 수 있었습니다!