본문 바로가기
반응형

Spring27

[REST API Client] Swagger doc 다른 서버 url 추가 - Java Spring REST API Client 개발 중에 Swagger doc으로 다른 서버에 request를 보내서 response를 받는 테스트를 해야할 때가 있었다. Swagger 테스트 중에 다른 서버를 추가하는 방법은 OpenApiConfig 클래스를 만들고 ArrayList에 request를 보내고자하는 서버 url(ip address, port) 추가하면 된다. @Configuration public class OpenApiConfig { @Bean public OpenAPI openAPiConfig() { ArrayList servers = new ArrayList(); servers.add(new Server().url("http://localhost:8080").description("Local Serv.. 2022. 12. 11.
What is DI(Dependency Injection), Why & How to use What DI(Dependency Injection): DI(Dependency Injection) is a core programming model supported by Spring Framework. Dependency is that one object uses another object. (depends on = uses) For example, if a QuestionController object uses a QuestionService object, The QuestionController object depends on the QuestionService object. public class QuestionController { private QuestionService questionSe.. 2022. 12. 9.
What is Dispatcher-Servlet, Why & How to use What is Dispatcher-Servlet: Dispatcher-Servlet is important in Spring MVC. Dispatcher-Servlet first gets client's requests and sends them to corresponding controller. Dispatcher-Servlet is called Front Controller. Why use Dispatcher-Servlet : To process common codes in each controller. To get all client requests using only a single dispatcher-servlet Don't have to use servlet in other controller.. 2022. 12. 8.
Dispatcher-Servlet(디스패처 서블릿) Dispatcher-Servlet이란(What): Dispatcher-Servlet은 Spring MVC에서 핵심이다. Dispatcher-Servlet은 클라이언트에서 들어오는 요청을 가장 먼저 처리하여 해당 컨트롤러에 전달한다. 프론트 컨트롤러(Front Controller)라고도 한다. Dispatcher-Servlet 사용하는 이유(Why): 디스패처 서블릿으로 인해 각 컨트롤러에 있는 공통 코드에 대해서 처리가 가능하다. 디스패처 서블릿 하나로 모든 클라이언트 요청을 받을 수 있기 때문 -> 들어오는 요청을 한 곳에서 다 받음 -> 편리함 디스패처 서블릿을 제외한 나머지 컨트롤러는 서블릿을 사용하지 않아도 되기 때문 Dispatcher-Servlet 사용하는 방법(How): 1. FrontCon.. 2022. 12. 8.
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.

반응형
반응형