Spring Framework
-
RestTemplate Get Request - RestTemplate Hands On 3Spring Framework/RestTemplate 2023. 9. 23. 00:01
개요 이전의 RestTemplate Get Request 파라미터 없는 요청에 대한 응답위주로 다루었다면 이번글은 QueryParam, PathVariable, Header 등 요청에 필요한 부가정보들을 어떻게 활용할 수 있는지 알아보고자 합니다. QueryParam 호출해보기 @GetMapping("/query-test-call") fun getQueryParamCall(@RequestParam param: Map): String { println(param) return "query" } Map으로 QueryParamater를 받는 api를 하나 준비했습니다. RestTemplate으로 queryParam 인자로 넘겨 호출하기 @GetMapping("/query-test") fun getQueryPa..
-
RestTemplate Get Request - RestTemplate Hands On 2Spring Framework/RestTemplate 2023. 9. 21. 00:01
개요 이전의 RestTemplate 생성과정에 이어 RestTemplate Get Request를 실습해보려 합니다. 글에서는 다음과 같은 테스트를 수행해 봅니다. Get으로 String 객체 호출해 보기 getForEntity와 getForObject의 차이점 String을 returnType으로 받지만 MyObject가 오는 경우 내가 원하는 필드만 발라내기 중첩 객체 필드도 받을 수 있는가 외부 호출 Controller 준비 @RestController class TestController { @GetMapping("/outer-call") fun outerCall(): String{ sleep(1000) return "process 1s job" } } // intellij HTTP plugin을..
-
RestTemplate이란? - RestTemplate Hands On 1Spring Framework/RestTemplate 2023. 9. 20. 00:01
개요 평소에 RestTemplate이란 기술을 알고 있었지만 FeignClient를 주로 활용하여 활용하곤 했습니다. 그러면 FeignClient를 더 학습하는게 좋을 텐데 굳이 RestTemplate을 학습하는 이유는 무엇일까요? 다른 개발자들은 Feign을 활용하는 대신 RestTemplate을 더 선호할 수 있습니다. RestTemplate을 활용하여 외부호출이 적용된 프로젝트들을 만날 수도 있습니다. RestTemplate을 활용하는 프로젝트를 만났기 때문에 이를 위해 공부해보고자 합니다. 이전에 FeignClient, WebClient, RestTemplate에 대해 비교하며 정리한글도 첨부해봅니다. RestTemplate이란? RestTemplate은 spring 3.0부터 등장한 기능입니다...
-
Spring Event 동작 원리 - 4Spring Framework 2023. 9. 16. 00:01
[1] Spring Event 동작 원리 - 1 [2] Spring Event 동작 원리 - 2 [3] Spring Event 동작 원리 - 3 이전 포스팅에 이어 EventListener에서 @Async는 어떻게 동작하는지 알아보고자 합니다. Spring Boot @Async @EnableASync, @Async 어노테이션을 활용하여 비동기 메서드로 동작을 수행할 수 있습니다. @Async는 AOP에 의해 동작하며 최종적으로는 AsyncExecutionAspectSupport클래스의 doSubmit 메서드를 통해 이루어집니다. AsyncExecutionAspectSupport 클래스 protected Object doSubmit(Callable task, AsyncTaskExecutor executor..
-
Spring Boot가 다중 요청을 처리하는 방법Spring Framework 2023. 9. 14. 00:01
개요Tomcat의 Thread에 대해 알아보다가 accept-count (작업큐의 사이즈)를 1로 설정했는데도 여러 개의 요청을 처리하는 모습을 보고 내부가 어떻게 동작하길래 이런 일이 가능한 건지 궁금해져서 알아보고자 합니다. accept-count란?max-connections 개수만큼 Tomcat 커넥터가 TCP 커넥션을 가지고 있을 때, 추가적인 요청이 오면 accept-count의 개수만큼 백로그에 저장합니다. (커넥션이 늘어나지는 않음) 스레드풀을 활용하여 요청을 처리한다!Queue에 Task를 담아두고 놀고 있는 스레드가 존재하면 해당 작업을 수행합니다. 여기서 accept-count는 Queue의 크기에 해당합니다. 이때 Queue에 크기를 1으로 설정하고, Thread의 크기를 1로 설..
-
Spring Event 동작 원리 -3Spring Framework 2023. 9. 13. 00:01
[1] Spring Event 동작 원리 - 1 [2] Spring Event 동작 원리 - 2 이전 포스팅에 이어 Spring EventListener의 등록과정에 대해 알아보고자 합니다. AbstractApplicationEventMulticaster protected Collection sourceType = (source != null ? source.getClass() : null); ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType); // Potential new retriever to populate CachedListenerRetriever newRetriever = null; // Quick check for ..
-
Spring Event 동작 원리 - 2Spring Framework 2023. 9. 12. 00:01
[1] Spring Event 동작 원리 - 1 이전 포스팅에 이어 invokeListener에 대해 알아보고자 합니다. InvokeListener 메서드 private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) { try { listener.onApplicationEvent(event); } } publishEvent가 발생한 후 메서드를 타고 들어가면 doInvokeListener 메서드가 호출되고 해당 메서드는 onApplicationEvent 메서드를 호출합니다. 어떻게 수많은 Entity 중 특정 Entity를 Consume 할 때만 실행될까? onApplicationEvent 메서드를 타고들어가보면 A..
-
Spring Event 동작 원리 - 1Spring Framework 2023. 9. 11. 00:01
개요 Spring이 제공하는 EventListener를 사용하다가 문득 Spring Event는 어떻게 동작하는 건지 궁금했었습니다. 추후에 비동기를 위해서는 @Async를 활용하는 대신에 ApplicationEventMulticaster를 사용할수도 있다는 이야기를 듣고 찾아보다가 Spring Event의 동작원리를 다룬 글을 보고 이 기회에 이해해 보고자 정리해보려 합니다. Application Context public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,MessageSource, ApplicationEventPublisher, ResourcePatter..