본문 바로가기
반응형

Spring31

Spring DI(Dependency Injection, 의존성 주입) DI란(What): 의존성 주입(DI)은 Spring Framework에서 지원하는 핵심 프로그래밍 모델이다. 의존성이 있다는 말은 한 객체가 다른 객체를 사용할 때 의존성이 있다고 한다. (의존한다 = 사용한다) 예를 들어, QuestionController 객체가 QuestionService를 사용하고 있는 경우, QuestionController가 QuestionService에 의존성이 있는 것이다. public class QuestionController { private QuestionService questionService; 의존성 주입이란 두 객체 간의 관계를 맺어주는 것이다. 객체를 직접 생성하는 것이 아닌 외부에서 객체를 생성 후 주입시켜준다. 의존성 주입에는 여러가지가 있다. 생성자 .. 2022. 12. 7.
Spring Security에서 세션값 변경 서비스에서 update를 통해서 수정을 해도 DB에는 수정이 되지만 세션 변경을 하지 않았기 때문에 브라우저에는 수정 전의 정보가 여전히 남는 문제가 생긴다. 새로 로그인을 해야 수정된 정보로 나타나게 되는데 그러한 번거러움 없이 세션값을 변경하면 수정 후 정보가 바로 반영된다. 세션값 변경을 적용하기에 앞서 SecurityConfig 클래스 내부에 메소드를 생성한다. @Configuration @EnableWebSecurity @RequiredArgsConstructor public class SecurityConfig { @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationCo.. 2022. 12. 3.
Spring Error: resolved [org.springframework.web.httpmediatypenotsupportedexception: content type '' not supported, Error: response status is 415 When I was using Swagger with Spring, I got error. Error: resolved [org.springframework.web.httpmediatypenotsupportedexception: content type '' not supported How I solved: Add consumes = ALL_VALUE inside @GetMapping parenthesis @Operation(description = "개인정보조회", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "/info", consumes = ALL_VALUE) public ResponseEntity menteeIn.. 2022. 12. 2.
Error: resolved [org.springframework.web.httpmediatypenotsupportedexception: content type '' not supported, Error: response status is 415 이전 글에서의 에러 상황 https://brightgarden02.com/entry/REST-API-%EB%B0%B1%EC%97%94%EB%93%9C%EC%97%90%EC%84%9C-%ED%94%84%EB%A1%A0%ED%8A%B8%EB%A1%9C-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%A0%84%EC%86%A1 Spring REST API 백엔드에서 프론트로 데이터 전송 백엔드와 프론트는 HTTP 통신을 통해 데이터를 주고 받으므로 백엔드 컨트롤러에서 ResponseEntity를 통해 감싸서 데이터를 전송한다 @RestController @RequiredArgsConstructor @RequestMapping(value = "/usr/mypage", consu brightGarden0.. 2022. 12. 1.
Spring REST API 백엔드에서 프론트로 데이터 전송 MenteeMyPageController에서 데이터 전송(백엔드 -> 프론트)을 하려고 한다 @RestController @RequiredArgsConstructor @RequestMapping(value = "/usr/mypage", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) @Tag(name = "MenteeMyPageController", description = "개인정보조회, 개인정보수정, 수강중인 클래스 정보 제공 기능을 담당") public class MenteeMyPageController { private final MenteeMyPageService menteeMyPageService; @Operation.. 2022. 12. 1.
Spring Security 로그인 문제 @Getter public class MemberContext extends User { private final Long id; private final LocalDateTime createDate; private final LocalDateTime modifyDate; private final String name; MemberContext에서 User를 상속받아 구현했다. 그런데 로그인이 안되는 에러가 생겼다. 디비에 저장이 안된건가 확인해봤다. 디비에는 잘 저장되어있다. 이유는 간단했다. MemberContext 클래스가 User를 상속받는데 User에 있는 username을 사용하기 때문이다. name이 아닌 username으로 사용해야했다. import org.springframework.se.. 2022. 11. 20.
[JPA] OneToMany 관계일 때 컬렉션 조회를 통한 쿼리성능개선 다음은 닥터 질문 답변 게시판 상황이다. 멤버는 질문을 할 수 있고 닥터는 답변을 달 수 있다. 질문과 답변은 OneToMany 관계이다. 여기서 문제는 질문 하나에 대해서 답변이 N개가 달린다면 N번의 쿼리가 나간다는 점이다. 답변 N개를 한번에 조회할 수 있는 방법이 있을까? 컬렉션 조회를 이용하면 된다. - 닥터 질문 답변 게시판 답변 쿼리는 다음과 같다. 문제점: 답변 쿼리를 조회하면 답변한 닥터 쿼리가 3번 나가게 된다. 질문 하나에 대해서 닥터 3명이 답변을 단 상황에서 OneToMany이므로 쿼리가 3번 나갔다. 이러면 성능에 문제가 생기기에 컬렉션 조회를 이용한다. 해결방안: application.yml 파일을 수정하자. jpa: hibernate: ddl-auto: update # 어플리.. 2022. 11. 5.

반응형
반응형