묻고 답해요
164만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결스프링 핵심 원리 - 기본편
AllBeanTest시, NoUniqueBeanDefinitionException 오류
AllBeanTest에서,강사님하고는 다른 오류가 뜹니다 ㅠ < 강사님 오류 > < 저의 오류 >org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl' defined in file [C:\study2\core\out\production\classes\hello\core\order\OrderServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'hello.core.discount.DiscountPolicy' available: expected single matching bean but found 2: fixDiscountPolicy,rateDiscountPolicy 라고 뜨는데, 왜 강사님과 다르게 저는 빈이 2개가 있다는 오류가 뜰까요?? ㅠㅠ orderServiceImplpackage hello.core.order; import hello.core.annotation.MainDiscountPolicy; import hello.core.discount.DiscountPolicy; import hello.core.member.Member; import hello.core.member.MemberRepository; import hello.core.member.MemoryMemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.stereotype.Component; @Component public class OrderServiceImpl implements OrderService{ private final MemberRepository memberRepository; private final DiscountPolicy discountPolicy; // final이 붙으면 필수값이 됨.@RequiredArgsConstructor는 필수값을 가지고 생성자를 만들어준다. @Autowired private DiscountPolicy rateDiscountPolicy; @Autowired public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) { this.memberRepository = memberRepository; this.discountPolicy = discountPolicy; } @Override public Order createOder(Long memberId, String itemName, int itemPrice) { Member member = memberRepository.findById(memberId); int discountPrice = discountPolicy.discount(member, itemPrice); return new Order(memberId, itemName, itemPrice, discountPrice); } public MemberRepository getMemberRepository(){ return memberRepository; } } RateDiscountPolicypackage hello.core.discount; import hello.core.annotation.MainDiscountPolicy; import hello.core.member.Grade; import hello.core.member.Member; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @Component public class RateDiscountPolicy implements DiscountPolicy{ private int discountPercent = 10; @Override public int discount(Member member, int price) { if(member.getGrade() == Grade.VIP){ return price * discountPercent / 100; } else { return 0; } } } FixDiscountPolicypackage hello.core.order; import hello.core.annotation.MainDiscountPolicy; import hello.core.discount.DiscountPolicy; import hello.core.member.Member; import hello.core.member.MemberRepository; import hello.core.member.MemoryMemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.stereotype.Component; @Component public class OrderServiceImpl implements OrderService{ private final MemberRepository memberRepository; private final DiscountPolicy discountPolicy; // final이 붙으면 필수값이 됨.@RequiredArgsConstructor는 필수값을 가지고 생성자를 만들어준다. @Autowired private DiscountPolicy rateDiscountPolicy; @Autowired public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) { this.memberRepository = memberRepository; this.discountPolicy = discountPolicy; } @Override public Order createOder(Long memberId, String itemName, int itemPrice) { Member member = memberRepository.findById(memberId); int discountPrice = discountPolicy.discount(member, itemPrice); return new Order(memberId, itemName, itemPrice, discountPrice); } public MemberRepository getMemberRepository(){ return memberRepository; } } AppConfigpackage hello.core; import hello.core.discount.DiscountPolicy; import hello.core.discount.FixDiscountPolicy; import hello.core.discount.RateDiscountPolicy; import hello.core.member.MemberService; import hello.core.member.MemberServiceImpl; import hello.core.member.MemoryMemberRepository; import hello.core.order.OrderService; import hello.core.order.OrderServiceImpl; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; // @Bean memberService -> new MemoryMemberRepository() // @Bean orderService -> new MemoryMemberRepository() // call AppConfig.memberService // call AppConfig.memberRepository // call AppConfig.memberRepository // call AppConfig.orderService // call AppConfig.memberRepository // 예상은 위와 같지만, 실제 실행된 것은 // call AppConfig.memberService // call AppConfig.memberRepository // call AppConfig.orderService @Configuration public class AppConfig { @Bean public MemberService memberService() { System.out.println("call AppConfig.memberService"); return new MemberServiceImpl(memberRepository()); } @Bean public MemoryMemberRepository memberRepository() { System.out.println("call AppConfig.memberRepository"); return new MemoryMemberRepository(); } @Bean public OrderService orderService() { System.out.println("call AppConfig.orderService"); return new OrderServiceImpl(memberRepository(), discountPolicy()); // return null; } @Bean public DiscountPolicy discountPolicy() { //return new FixDiscountPolicy(); return new RateDiscountPolicy(); } } AllbeanTestpackage hello.core.Autowired; 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; import static org.assertj.core.api.Assertions.*; 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 discountPrice = discountService.discount(member, 10000, "fixDiscountPolicy"); // discount가 얼마나 되는지 보는 서비스 assertThat(discountService).isInstanceOf(DiscountService.class); assertThat(discountPrice).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 i, String fixDiscountPolicy) { return 0; } } }
-
해결됨풀스택 리액트 라이브코딩 - 간단한 쇼핑몰 만들기
routes.tsx에서 질문이 있습니다!
라우츠 파일에 보면 제일 밑에 코드에서 pages 를 익스포트해주는데, 쓰는곳이 없더라구요...!혹시 이 코드가 반드시 필요한 것인지 궁금해서 질문 남깁니다:)import GlobalLayout from './pages/_layout'; import Index from './pages/index'; import ProductsIndex from './pages/products/index'; import ProductsId from './pages/products/[id]'; import Cart from './pages/cart'; export const routes = [ { path: '/', element: <GlobalLayout />, children: [ { path: '/', element: <Index />, index: true }, { path: '/products', element: <ProductsIndex />, index: true }, { path: '/products/:id', element: <ProductsId /> }, { path: '/cart', element: <Cart />, index: true }, ], }, ]; export const pages = [{ route: '/' }, { route: '/products' }, { route: '/products/:id' }, { route: '/cart' }];
-
해결됨직장인에게 꼭 필요한 파이썬-아래아한글 자동화 레시피
누름틀 없는 한글문서 엑셀로 취합하기 응용 질문드려요
해당 강의 잘 보고 응용해보려고 하는데 잘 풀리지 않는 부분이 있어 문의 드립니다.제가 자동화하고자 하는 파일은 예시의 서식이 여러파일형태로 존재하는 게 아니라 한 파일안에 동일한 양식의 표가 반복되는 형태인데요.동일한 양식의 표를 엑셀에 항목별로 입력하고자 합니다.강의로 예를 들면 강의에서는 용역과제 심의신청서가 각 파일에 1개씩 이어서 폴더내의 파일을 하나하나 열면서 안의 내용을 리스트로 정리하고, 리스트 중 옮길 값을 추출했지만제 경우에는 용역과제 심의신청서가 한 파일에 모두 모여있는 경우라고 할 수 있을 것 같습니다.그래서 파일안에 있는 텍스트를 모두 추출하여 list화 까지는 수행했는데, 거기서 엑셀로 옮길 값만 추출하는데 있어서 어떤 규칙성을 찾기가 어려워서 어떻게 해야할지 좀 막막하네요...예를 들면 예시에서 과제명이 contents[1]이었으면 다음 표에서는 과제명이 contents[26] (<-연구결과활용방안다음)이어야 하는데 중간중간 끊기는 부분이 있는지 갑자기 contents[27]이라던가 번호가 하나씩 밀리는 문제가 발생합니다.이런 경우에는 어떤 for문으로 반복되는 표 양식 안의 내용을 가져올 수 있을까요..?
-
해결됨[라이브 멘토링] 유니티 뱀파이어 서바이벌 장르 모작
안녕하세요. 7월 예정강의에 대해 질문이 있습니다.
유니티 & 웹서버(키우기 게임 + 웹서버) 강의가 7월 예정으로 들었는데 항상 강의 전달 말쯤에소식이 들렸는데 이번엔 아직 소식이 없어서 질문드립니다!관련해서 예정이 있으신건가요?
-
미해결토비의 스프링 부트 - 이해와 원리
테스트시에 나오는 문제
안녕하세요. 토비님스프링부트로 api테스트시에 가끔식 400 Bad Request 가 나오는데요.호출하는 header와 body는 모두 동일한데, 2~30번 호출 중에 한번씩 튀어나오는 경우는 어떤 설정에 문제일까요?api 내용은 별게 없고 로그를 다 찍기도 전에 앞에서 400에러가 나는 상황입니다. 혹시 관련해서 경험하신 바가 있으신지 궁금합니다.
-
미해결SCSS(SASS)+FLEX 실전 반응형 웹 프로젝트 with Figma
강의 자료가 열리지 않습니다.
안녕하세요~디자인 작업(beyound+insight) > 피그마(Figma)원본 폴더 안에 있는 두 개 파일이 열리지 않아서요.어떻게 볼 수 있을까요~?
-
미해결아두이노 시작하기
3색 led 아두이노 연결ㄹ
영상에서 3색 led를 아두이노를 연결할 떄, 아두이노의 5V도 빵판에 연결시키셨는데, 5V의 역할은 무엇인지 궁금합니다. 그냥 LED에서는 5V연결이 없었는데, 3색 LED에서는 5V연결이 필요한 것인지도 궁금하네요.
-
미해결홍정모의 따라하며 배우는 C언어
강의 4:29 0.01f 위에 커서를 올렸을 때
강의의 경우 (float)(0.009999999776F)라고 뜨는데왜 저는 그냥 단순하게 (flat)(0.01F)라고 뜰까요?비쥬얼스튜디오에서 따로 설정해야하는건가요?
-
미해결이득우의 언리얼 프로그래밍 Part1 - 언리얼 C++의 이해
VS2022 Always show Error List if... 옵션을 끄는 이유
강의 10:13 부분에서 VS2022 옵션 중 Always show Error List if build finishes with errors 를 끄시는 데.. 옵션 내용만 보면 켜놓는 게 좋을 것 같다고 생각이 드는데요. 왜 끄는 지 이유를 알수 있을까요.
-
해결됨10주완성 C++ 코딩테스트 | 알고리즘 코딩테스트
8 - L 질문입니다.
안녕하세요 선생님! 8주차와서 많은 질문으로 찾아뵙는 것 같습니다... 항상 감사합니다.http://boj.kr/f01a3b3704f147638cb5d548fbe26459바로 이전 문제였던 8 - K의 풀이처럼 펜윅트리를 행별로 형성하게 해서 코드를 짜보았습니다. 테스트케이스는 잘 통과하는데 틀렸습니다...ㅠ 혹시 제 코드에서 어떤 점이 문제였을지 알 수 있을까요?
-
미해결실전! Querydsl
sort관련 질문드립니다.
직접 파라미터를 받아 처리하는걸 권장 한다고 하셨는데 @Data public class MemberSearchDto { private String username; private String teamName; private Integer ageGoe; private Integer ageLoe; private String sort; private String orderBy; } sort=desc; orderby=username 으로 값을 받는다면 .orderBy(addSort(searchDto.getSort(),searchDto.getOrderBy())) private OrderSpecifier<?> addSort(String sort, String orderBy) { if(StringUtils.hasText(sort) && StringUtils.hasText(orderBy) && (sort.equals("desc") || sort.equals("asc"))){ if(orderBy.equals("username")){ return sort.equals("desc") ? member.username.desc() : member.username.asc(); } } return member.age.desc(); } 이런식으로 처리하면 되는지 궁금합니다.
-
해결됨스프링 DB 1편 - 데이터 접근 핵심 원리
트랜잭션 범위 최소화
안녕하세요. 영한님궁금한게 생겨 질문 드립니다.! 일반적으로 서비스 레이어에서 @Transactional(AOP 기술)을 사용하여 트랜잭션을 걸어주는데, DB 조회와 관련된 로직에서 트랜잭션이 없어도 될것 같은 생각이 듭니다. DB 조회에서 트랜잭션을 수행하지 않는 방법이 있을까요?다시 말씀드리면, 트랜잭션 범위를 최소화 하려면 어떻게 해야할까요?제가 생각한 방법은 트랜잭션이 필요한 부분과 필요하지 않은 부분을 분리하는 것이 있을 것 같습니다.현업에서는 어떻게 해결하는지 궁금 합니다.🤔 예를 들어 아래와 같은 로직에서1,2,3에서는 트랜잭션이 필요 없을것으로 판단됩니다.@Service public class OrderService { @Transactional public void order() { /** * 1. 회원 조회 * 2. 배송 가능한 지역인지 조회 * 3. 상품 조회 * 4. 배송 생성 * 5. 결제 생성 * 6. 주문 생성 */ } } 4,5,6에만 트랜잭션이 필요하다고 생각이 됩니다.@Service public class OrderService { @Transactional public void order() { /** * 1. 회원 조회 * 2. 배송 가능한 지역인지 조회 * 3. 상품 조회 * * // 트랜잭션 시작 * 4. 배송 생성 * 5. 결제 생성 * 6. 주문 생성 * // 트랜잭션 종료 */ } } 감사합니다.
-
해결됨ProtoPie Master Courses (프로토파이 마스터 클래스)
하단 팝업 부분을 그냥 탭 했을 때도 닫히는데,
dim 부분만 탭 했을 때, 꺼지도록 하는 방법은 따로 없을까요?..
-
미해결나도코딩의 자바 기본편 - 풀코스 (20시간)
패키지 부문에서 로또 생성번호하는 과정에서 질문이 있습니다.
System.out.print("랜덤 로또 번호 : ");for (int i = 0; i < 6; i++) {System.out.print((random.nextInt(45) + 1));System.out.print(" ");6개의 숫자를 동시에 생성 해보려고 for 문 이용해서 숫자를 생성 해봤는데 중복된 숫자들이 나열되는 경우들이 있더라구요. 이럴경우 숫자가 중복되지 않게 나오게 하는 방법이 있을까요?
-
해결됨최신 딥러닝 기술 Vision Transformer 개념부터 Pytorch 구현까지
헷갈리는게 몇개 있습니다ㅠㅠ
안녕하세요 강사님.Transformer 에 대해 처음 공부해보니 헷갈리는 부분들이 있어서 질문남깁니다.1) k 개의 Multi-Head를 만든 후에 Linear를 해주는 이유가 따로 있는지 궁금합니다. 단순히 Residual Connection을 위해 차원을 맞춰주기 위해 하는 것인가요??2) Head의 개수(k)는 CNN에서 필터 개수처럼 사용자가 정해주는 파라미터인가요??3) 클래스 토큰까지 Positional Embedding을 더해줘야 하는 이유가 따로 있을까요??좋은 강의 덕분에 따라가긴 하는데 한 번에 이해하려하니 과부하가 와서 헷갈리는게 생기네요ㅠㅠ코드 분석 파트 들어가면 조금 더 이해가 될 것 같은데 우선적으로 질문남겨봅니다.
-
미해결[C++과 언리얼로 만드는 MMORPG 게임 개발 시리즈] Part2: 게임 수학과 DirectX12
디버그 출력창 에러
항상 좋은 수업 정말 감사합니다.다름이 아니라 Camera 강의를 듣는 도중 출력창에 에러가 떠서 궁금하여 질문드립니다.실행은 잘 되지만 선생님께서 제공해주신 예제 또한 같은 에러가 창에 출력되어 딱히 문제가 되는 것은 아닌지 궁금합니다. 이후에도 제공해주신 예제에서 같은 오류가 뜨는 거 같아 질문 드립니다.
-
미해결스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술
Jpa강의 듣던중 .setParameter를 사용하는 이유가 궁금합니다.
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.1. 강의 내용과 관련된 질문을 남겨주세요.2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.(자주 하는 질문 링크: https://bit.ly/3fX6ygx)3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.=========================================[질문 템플릿]1. 강의 내용과 관련된 질문인가요? (예/아니오)2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)[질문 내용]JpaMemberRepository에서 FindByName 메서드를 보면 .setParameter후에 .getResultList()를 사용하는데 setParameter를 사용하는 이유가 궁금합니다!
-
미해결스프링 시큐리티
스프링부트 dependencies 필요하신분
//타임리프 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' // 스프링 시큐리티 implementation 'org.springframework.boot:spring-boot-starter-security' //jpa implementation 'org.springframework.boot:spring-boot-starter-data-jpa' //web implementation 'org.springframework.boot:spring-boot-starter-web' //postgresql 드라이버 runtimeOnly 'org.postgresql:postgresql' //모델 mapper implementation 'org.modelmapper:modelmapper:3.1.1' // lombok compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' // devtools developmentOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test'
-
미해결자바스크립트 알고리즘 문제풀이 입문(코딩테스트 대비)
코드 리뷰 부탁 드립니다.
<script> function solution(arr) { let answer = 0; let cross = 0; for (let i = 0; i < arr.length; i++) { cross += arr[i][i]; let hang = 0; let yuel = 0; for (let j = 0; j < arr.length; j++) { hang += arr[i][j]; yuel += arr[j][i]; } if (answer < hang) { answer = hang; } if (answer < yuel) { answer = yuel; } // console.log(answer, tu); } return answer < cross ? cross : answer; } let arr = [ [10, 13, 10, 12, 15], [12, 39, 30, 23, 11], [11, 25, 50, 53, 15], [19, 27, 29, 37, 27], [19, 13, 30, 13, 19], ]; console.log(solution(arr));
-
해결됨외워서 끝내는 네트워크 핵심이론 - 기초
DNS cache에 관하여
선생님! DNS 수업 중에 말씀하신 DNS Cache를 확인해보고 싶어서 봤더니 www.naver.com에 해당하는건 안보이는데 이건 어떻게 된걸까요? 제가 네이버에 접속 후 $ipconfig /displaydns를 했는데 알 수 없는 이상한 이름의 도메인이 뜨네요.