묻고 답해요
169만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
해결됨스프링 핵심 원리 - 기본편
스프링 컨테이너 생성 시 DI 컨테이너를 인스턴스로 생성하지 않고 .class로 생성하는 이유가 궁금합니다.
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.1. 강의 내용과 관련된 질문을 남겨주세요.2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.(자주 하는 질문 링크: https://bit.ly/3fX6ygx)3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.=========================================[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오)2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)[질문 내용]안녕하세요 강의 내용 중 아래의 방법으로 스프링 컨테이너를 생성할 수 있었습니다.ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);그런데 AnnotationConfigApplicationContext는 new를 통해 런타임 시점에 초기화가 되는데 AppConfig는 왜 new AppConfig()가 아닌 AppConfig.class 로 클래스 명세만을 필요로하는지 궁금합니다.가령 아래와 같이 AppConfig를 런타임 시점에 생성하여 Bean을 등록하는 것도 가능해야 할 것 같은데 AppConfig.class로 스프링 컨테이너를 생성할 시 어떤 이점이나 효과가 있어서 AppConfig 인스턴스를 통해 스프링 컨테이너를 생성하는 것을 제한하였는지 궁금합니다.ApplicationContext applicationContext = new AnnotationConfigApplicationContext(new AppConfig());
-
미해결스프링 핵심 원리 - 기본편
AutoAppConfig 역할
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.1. 강의 내용과 관련된 질문을 남겨주세요.2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.(자주 하는 질문 링크: https://bit.ly/3fX6ygx)3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.=========================================[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오)2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)[질문 내용]new AnnotationConfigApplicationContext(AutoAppConfig.class);코드가 실행되면서 AutoAppConfig 자체가 빈으로 등록이 되면서 AutoAppConfig빈은 @ComponentScan이라는 어노테이션을 써주면서 컴포넌트를 스캔하는 역할을 하게 되는건가요?즉, AutoAppConfig빈은 ComponentScan라고 생각해두 되나요?
-
미해결스프링 핵심 원리 - 기본편
섹션 9 빈 스코프 질문입니다.
1.프로토타입 스코프 11분 28초에 preDestory같은 메소드가 실행되지 않는다고 했는데요.ac.close(); 이건 preDestory가 아닌가요? 2.프로토타입 스코프 11분 28초싱글톤 빈은 하나의 빈으로 종료까지 관여 하는거고 프로토타입스코프는 여러개의 빈이 생성되고 초기화까지만 관여하는걸로 이해해 도 되나요?3.프로토타입 스코프 10분 강의 똑같이 따라 쳤는데 아래와 같은 에러가나옵니다. 뭐가 문제인건가요?package hello.core.scope; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Scope; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; public class PrototypeTest { @Test void prototypeBeanFind(){ AnnotationConfigApplicationContext ac =new AnnotationConfigApplicationContext(PrototypeBean.class); PrototypeBean prototypeBean1=ac.getBean(PrototypeBean.class); PrototypeBean prototypeBean2=ac.getBean(PrototypeBean.class); System.out.println("prototypeBean2 = " + prototypeBean2); System.out.println("prototypeBean1 = " + prototypeBean1); Assertions.assertThat(prototypeBean2).isNotSameAs(prototypeBean1);//똑같은 인스턴스가 출력됨. ac.close(); } @Scope("Prototype") static class PrototypeBean{ @PostConstruct public void init(){ System.out.println("Prototype.init"); } @PreDestroy public void destory(){ System.out.println("Prototype.destory"); } } }java.lang.IllegalStateException: No Scope registered for scope name 'Prototype'이런에러가 나오는데 뭐가문제인가요?4.파란색선인 프로토타입이닛보다 빨간색프로토타입 빈2가 더빨리 나와야 하는거 아닌가요?println이 더 먼저 있는데요.
-
미해결스프링 핵심 원리 - 기본편
섹션 8 생명주기 강의 질문입니다.
1.빈 생명주기 콜백 시작 9분에서 아래와 같은 3개 단어가 나오는데요.ConfigurableApplicationContext가 최상위 인터페이스고ApplicationContextAnnotationConfigApplicationContext이런 순으로 자식관계가 형성되어있는건가요? 빈 생명주기 콜백 시작 13분에서 스프링빈은 객체 생성후 의존관계주입이 되는데 생성자는 예외라고 하셨는데요. 생성자가 스프링빈을 이미 생성해서 스프링 빈이 같이 들어와야 되기 때문에 파라미터의 예외라고 하셨는데요. 혹시 코드로 예시좀 보여주실 수 있나요? 3.인터페이스 InitializingBean, DisposableBean 3분에서 위와 같은 코드가 나오는데요. 위코드가 의존관계 주입이라는건가요?
-
미해결스프링 핵심 원리 - 기본편
조회한 빈이 모두 필요할 때, List, Map 강의 질문있습니다.
package hello.core.autowaried; import hello.core.AutoAppconfig; import hello.core.discount.DiscountPolicy; import hello.core.member.Grade; import hello.core.member.Member; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import java.util.List; import java.util.Map; public class AllBeanTest { @Test void findAllbean(){ ApplicationContext ac= new AnnotationConfigApplicationContext(AutoAppconfig.class,DiscountService.class); DiscountService DiscountService=ac.getBean(DiscountService.class); Member member=new Member(1l,"userA", Grade.VIP); int dinscountPrice=DiscountService.discount(member,10000,"fixDiscountPlicy"); Assertions.assertThat(DiscountService).isInstanceOf(DiscountService.class); Assertions.assertThat(dinscountPrice).isEqualTo(1000); } static class DiscountService{ private final Map<String, DiscountPolicy> policyMap; private final List<DiscountPolicy> policies; @Autowired public DiscountService(Map<String, DiscountPolicy> policyMap, List<DiscountPolicy> policies) { this.policyMap = policyMap; this.policies = policies; System.out.println("policyMap = " + policyMap); System.out.println("policies = " + policies); } public int discount(Member member, int price, String discountCode) { DiscountPolicy discountPolicy=policyMap.get(discountCode); return discountPolicy.discount(member,price); } } } 해당강의에서 8분 52초를 따라하고 있는데 아래같은 에러가 나옵니다. 근데 강의 초반부에 나오는policyMap,policies는 제대로 출력이 됬는데 어디가 잘못된걸까요? 강의와 다르게 discountService를 DiscountService로 등록했는데 왜 에러 없이 잘 되나요? DiscountService DiscountService <=보통 DiscountService discountService 이렇게 선언되어야 하지 않나요?@Test void findAllbean(){ ApplicationContext ac= new AnnotationConfigApplicationContext(AutoAppconfig.class,DiscountService.class); DiscountService DiscountService=ac.getBean(DiscountService.class); Member member=new Member(1l,"userA", Grade.VIP); int dinscountPrice=DiscountService.discount(member,10000,"fixDiscountPlicy"); Assertions.assertThat(DiscountService).isInstanceOf(DiscountService.class); Assertions.assertThat(dinscountPrice).isEqualTo(1000); }
-
미해결나도코딩의 자바 기본편 - 풀코스 (20시간)
전달값 반환값 차이
반환값이 없는 경우에는 Void를 사용하고 전달값을 쓴다.반환값 return이 있는 경우에는 반환에 따라 Int / String/Double 을 사용한다까지 제가 이해를 한 부분인데...public static void power (int number) public static String getPhoneNumber() 어떤 차이에 따라 어떻게 사용되는지를 잘모르겠습니다.ㅠㅠ
-
미해결스프링 핵심 원리 - 기본편
Extract Method 저는 다른 단축키였군요
[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오)2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)[질문 내용]여기에 질문 내용을 남겨주세요. Geforce Experience 앱 삭제해봐도 안되고 별 검색 다 해보다가 오른쪽 마우스 클릭하니 refactor 가 떡하니 있었어요 alt + shift + m 이었네요 왜 저만 다른걸까요? 설정을 해야하는건가요?
-
미해결스프링 핵심 원리 - 기본편
Bean 등록시 궁금한점이 생겼습니다.
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.1. 강의 내용과 관련된 질문을 남겨주세요.2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.(자주 하는 질문 링크: https://bit.ly/3fX6ygx)3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.=========================================[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오)2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)[질문 내용]위 코드상황만 봤을때bean 등록시 memberService를 호출하는 동시에 memberRepository를 호출하면서 의존관계도 설정이 된다고 이해했습니다.그렇다면@Bean public MemoryMemberRepository memberRepository() { return new MemoryMemberRepository(); }위의 메서드에 bean어노테이션이 없어도 memberRepository는 bean객체로 관리가 되나여 ???또한 위의 메서드를 지우고@Bean //각메서드에 bean이라 적으면 각 메서드가 스프링컨테이너에 등록이 된다. public MemberService memberService(){ return new MemberServiceImpl(new MemoryMemberRepository()); }위와 같이 수정해도 bean으로 관리가 되나요 ?
-
미해결나도코딩의 자바 기본편 - 풀코스 (20시간)
섹션 12 에러 (코드는 같은데 선생님만 에러 안 뜸)
섹션 12 예외처리 사용자 정의 예외에서 AgeLessThan19Exception가 선생님 화면에는 에러없이 잘 넘어가지만, 실제로는 클래스를 따로 분리하거나 static class AgeLessThan19Exception를 사용해야하는거 아닌가요? 전 에러때문에 코드 실행이 아예 안됩니다.
-
미해결스프링 핵심 원리 - 기본편
섹터 7강 의존관계 자동 주입 질문있습니다.
@Autowired 필드 명, @Qualifier, @Primary 12분에서 빨간색 네모표시된 커넥션 빈을 획득한다는게 무슨의미인가요?
-
미해결나도코딩의 자바 기본편 - 풀코스 (20시간)
_Quiz_10에 질문 있습니다. ㅠㅠ
안녕하세요.. 혼자 문제 풀다가 결국 너무 막혀서 답변을 보고 이해를 했는데,, String[] names = {"챈들러", "레이첼", "모니카", "벤자민", "제임스"}; int[] ages = {50, 42, 21, 18, 5}; Arrays.stream(ages) .filter(x->x>=20) .map(x-> x >= 20 ? names + " 5000원": names + " 무료") .forEach(System.out::println); 혹시 이런 코드로 풀 수 있는 방법같은게 없을까요? 이거저거 하다가 다 안돼서 결국 사용하신 방법으로 이해는 했는데 2개의 리스트를 하나의 출력문으로 할 수 있는 방법이 없을까 해서 질문 드립니다.
-
미해결스프링 핵심 원리 - 기본편
discountFixAmount 왜 오류뜰까요ㅠㅠㅠ(주문과 할인 도메인 개발, 2분쯤에요)
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.1. 강의 내용과 관련된 질문을 남겨주세요.2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.(자주 하는 질문 링크: https://bit.ly/3fX6ygx)3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.=========================================[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오) 예2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오) 예3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오) 예[질문 내용]똑같이 따라쳤는데 이렇게 나오네요ㅠㅠㅠ 이유가 뭘까요..
-
미해결스프링 핵심 원리 - 기본편
9 - 프로토 타입 스코프를 싱글톤 빈과 함께 사용시 문제점 강의중 질문
질문 1. 아래코드에서 ClientBean이 내부 메서드에서 prototypeBean을 사용할 수 있는 이유?static class ClientBean{ ... }의 코드에서는 스프링 빈으로 prototypeBean을 등록하는 부분이 없는데 어떻게 logic()메소드에서 prototypeBean.addCount();를 사용할 수 있는 것인가요? 🤔 제 생각에는 void singletonClientUsePrototype()의 코드인 AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ClientBean.class, PrototypeBean.class); 으로 빈으로 등록이 되는 것 같아서 코드를 다음과 같이 수정 후 실행해 보았습니다.AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ClientBean.class); 👉 그러자 실행이 안되는 것을 확인 할 수 있었습니다. 질문 2. singletonClientUsePrototype()메소드에서 등록된 빈이 ClientBean에 어떻게 영향을 주는 것인가요?🤔 ClientBean 코드의 ApplicationContext applicationContext;의 의존성 주입을 통해 이루어지는 것 같은데 이 코드에서는 어떤 것이 applicationContext에 해당되는 것인가요..? 따로 해당 인스턴스타입으로 등록된 빈이 없는 것 같은데 헷갈립니다ㅜㅜ public class SingletonWithPrototypeTest1 { @Test void singletonClientUsePrototype(){ AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ClientBean.class, PrototypeBean.class); ClientBean client1 = ac.getBean(ClientBean.class); int count1 = client1.logic(); assertThat(count1).isEqualTo(1); System.out.println("count1 = " + count1); ClientBean client2 = ac.getBean(ClientBean.class); int count2 = client2.logic(); System.out.println("count2 = " + count2); assertThat(count2).isEqualTo(1); } @Scope("singleton") static class ClientBean { @Autowired ApplicationContext applicationContext; public int logic() { PrototypeBean prototypeBean = applicationContext.getBean(PrototypeBean.class); prototypeBean.addCount(); return prototypeBean.getCount(); } } @Scope("prototype") static class PrototypeBean { private int count = 0; public void addCount() { count++; } public int getCount() { return count; } @PostConstruct public void init() { System.out.println("PrototypeBean.init" + this); } @PreDestroy public void destroy() { System.out.println("PrototypeBean.destroy"); } } }
-
미해결스프링 핵심 원리 - 기본편
섹터 7강 의존관계 자동 주입 질문있습니다.
1.생성자 주입을 선택해라! 강의에서 4분22초에서 에러가 왜 나는건가요? 매개변수를 3개를 줘서 그런건가요? 2.@Autowired 필드 명, @Qualifier, @Primary 1분 56초에서 basic scan에서 왜 오류가 나는건가요?orderserviceimpl에서 discountplicy를 ratediscountplicy로 바꾸면 오류가 안나는데 왜 오류가 안나는건가요?
-
미해결스프링 핵심 원리 - 기본편
SRP는 이렇게 생각하면될까요?
예를 들자면 컨트롤러는 컨트롤러의 역할만 가져야하고서비스는 서비스의 역할만 가져야한다 이렇게 이해하면될까요?
-
미해결스프링 핵심 원리 - 기본편
@SpringBootApplication 로 실행시 궁금한 점이 있습니다.
위 사진은 @SpringBootApplication 이 달린 Core3Application을 실행해본 후 스프링컨테이너 내부에 어떤 스프링빈이 있는지 확인하는 코드입니다. 여기서 궁금한 점이 Core3Application을 실행하면서 MemoryMemberRepository 와 같이 @Component 어노테이션이 붙은 클래스들은 @SpringBootApplication 에 있는 컴포넌트 스캔에 의해서 한 번, AutoAppConfig가 스프링빈으로 등록되면서 AutoAppConfig의 컴포넌트스캔이 작동하여 총 두 번 중복으로 등록되어진다고 생각되는데 이 경우에는 왜 빈 충돌 오류 메세지가 발생하지 않았는지 궁금합니다.
-
미해결홍정모의 게임 만들기 연습 문제 패키지
예제코드
예제 코드는 어디서 다운 받아볼 수 있을까요 ?
-
미해결스프링 핵심 원리 - 기본편
섹션 7 의존관계 자동 주입 질문있습니다.
다양한 의존관계 주입 방법 3분11초에서요.생성자를 통해서만 이 의존관계가 주입된다는데 생성자는 뭐고 의존관계는 뭔가요?
-
미해결스프링 핵심 원리 - 기본편
섹터 6 컴포넌트 스캔 질문있습니다.
필터에서요.public class ComponentFilterAppConfigTest { @Test void filterScan(){ ApplicationContext ac= new AnnotationConfigApplicationContext(ComponentFilterAppConfig.class); BeanA beanA =ac.getBean("BeanA",BeanA.class); Assertions.assertThat(beanA).isNull(); BeanB beanB =ac.getBean("BeanB",BeanB.class); org.junit.jupiter.api.Assertions.assertThrows(NoSuchBeanDefinitionException.class,()->ac.getBean("BeanB",BeanB.class)); } @Configuration @ComponentScan( includeFilters = @ComponentScan.Filter(type= FilterType.ANNOTATION,classes = MyIncludeComponent.class), excludeFilters=@ComponentScan.Filter(type=FilterType.ANNOTATION,classes = MyExcludeComponent.class) ) static class ComponentFilterAppConfig{ }}org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'BeanA' available에러 왜나는 건가요?BeanA beanA =ac.getBean("BeanA",BeanA.class); 여기서 BeanA beanA =ac.getBean("beanA",BeanA.class);이렇게 하면 에러가 안나는데요. BeanAclass를 호출하는거 아닌가요? 2.윗 부분 추가 질문있습니ㅏㄷ.org.junit.jupiter.api.Assertions.assertThrows(NoSuchBeanDefinitionException.class,()->ac.getBean("BeanB",BeanB.class));(NoSuchBeanDefinitionException 이 뒤에 class 왜붙이는거에요? 그냥ac.getBean("BeanB",BeanB.class) 실행 시 에러값(NoSuchBeanDefinitionException)이 있을 때 예외처리하는거 아닌가요? class로 또 참조하는게 있나요?3. 중복 등록과 충돌spring.main.allow-bean-definition-overriding=true 이걸 작성하지 않는이상 수동빈 등록할 때 오류가 나는걸로 이해해도 되나요?
-
해결됨나도코딩의 자바 기본편 - 풀코스 (20시간)
chap 7 Class 강의 05MethodOverloading 마지막 부분에서 보여주는 .IndeOf에 컨트롤 누르고 들어가는 화면이 궁금합니다.
해당화면은 어떠한 기능을 가지는지 궁금합니다. 인텔리제이에서 제공하는 기능들을 보여주는건가요??