Skip to content
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 미션 제출합니다. #3

Open
wants to merge 4 commits into
base: limdodod
Choose a base branch
from

Conversation

limdodod
Copy link

No description provided.

Unverified

This user has not yet uploaded their public signing key.
README.md Outdated
@Service
public class UserService {

private UserRepository userRepository;
Copy link

@Gothax Gothax Mar 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자 주입 시 final 제한자를 사용하면 좋을 것 같습니다!

final을 사용하면 불변성을 보장할 수 있고
초기화를 강제하기 때문에 컴파일 시점에 누락된 의존성을 확인할 수 있습니다.

좋은 글이 있어서 공유합니다!!
https://mangkyu.tistory.com/125

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그러게요 뺴먹었네요 !! 감사합니다 :)


3️⃣ 필드 주입

( 2️⃣,3️⃣은 의존성이 없어도 객체가 생성될 수 있어 권장하지 않음!)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

순환 참조 문제도 공부해 보면 좋을 것 같습니다~!

Copy link
Author

@limdodod limdodod Mar 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요 !

순환참조 문제란 A 클래스가 B 클래스의 Bean 을 주입받고, B 클래스가 A 클래스의 Bean 을 주입받는 상황처럼 서로 순환되어 참조할 경우 발생하는 문제입니다.

생성자 주입은 객체 생성 시점에 의존 관계가 확정돼서 실행시점에 순환 참조가 감지되는데 Setter 주입이나 필드 주입은 런타임 시점에 주입돼서 런타임에 오류가 발생해 지양하는걸로 알고 있습니당 ~~


@Repository: DAO 역할을 하는 클래스에 사용

@Service: 비즈니스 로직을 담당하는 클래스에 사용
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정리👍입니다

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정리해주셔서 감사합니다 ㅠㅠ 공부할 때 참고할게용

Copy link

@Gothax Gothax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

Copy link
Collaborator

@limgahyun limgahyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1주차 과제 너무 고생하셨습니다아 🔥🔥🔥

Comment on lines +1 to +6
spring:
datasource:
url: jdbc:h2:tcp://localhost/~/ceos21
username: sa
password:
driver-class-name: org.h2.Driver
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보안을 위해 .ginignore를 활용해보면 좋을 것 같아요!!

import jakarta.persistence.Id;
import lombok.Data;

@Data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaTa 어노테이션의 기능에는 뭐가 있나요??!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오옹 잘 몰랐는데
@Getter / @Setter, @tostring, @EqualsAndHashCode@requiredargsconstructor, @value 를 합쳐놓은 것이라고 나오네요 ..!
근데 Setter 남용 문제 때문에 사용을 지양한다고 하는군요!!

Comment on lines +80 to +82
- @ComponentScan
: @Component, @Service, @Repository, @Controller, @Configuration이 붙은 빈들을 찾아서
Context에 빈을 등록해 주는 어노테이션 (@SpringBootApplication에 포함)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@componentscan 어노테이션이 위의 어노테이션이 붙은 빈들을 탐색한다고 정리해주셨는데, 그럼 그냥 해당 프로젝트 내에 모든 범위를 탐색할까요?! 어느 파일, 어느 범위까지 탐색하는지도 알아두면 좋을 것 같아요 !

Copy link
Author

@limdodod limdodod Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기본적으로 @SpringBootApplication이 선언된 클래스가 있는 패키지 기준으로 탐색합니다.
빈이 다른 패키지에 있으면 인식되지 않을 수 있어서
그럴 때는 명시적으로 @componentscan을 사용하여 스캔 범위를 설정할 수 있습니다 ~!

@componentscan(
basePackages = "basic.server",
)

이런식으로, basePackages를 사용해 탐색할 패키지의 시작위치를 정하면, 이 패키지를 포함한 하위 패키지를 모두 탐색해 @component가 있는지를 확인합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants