2022-11-12-TIL

Today I Learned

@Conmponent(자동주입, 자동 빈 등록) vs @Bean(수동주입, 수동 빈 등록)

  • https://stackoverflow.com/questions/10604298/spring-component-versus-bean
  • https://www.danvega.dev/blog/2017/05/17/spring-component-vs-bean/
  • https://docs.spring.io/spring-javaconfig/docs/1.0.0.m3/reference/html/creating-bean-definitions.html
  • https://www.baeldung.com/spring-bean-annotations
  • https://www.inflearn.com/questions/307394
  • https://applepick.tistory.com/132
  • https://taehoung0102.tistory.com/75
  • https://velog.io/@wisepine/Spring-%EC%9E%90%EB%8F%99-vs-%EC%88%98%EB%8F%99-%EB%B9%88-%EB%93%B1%EB%A1%9D

Kotlin @field:NotNull

코틀린에서는 NotNull 애너테이션을 붙이더라도 기본적으로 null을 허용하지 않으므로 코틀린 내부에러가 발생한다. 따라서 null값을 받으면 검증하기 어렵다. 따라서 현재는 애너테이션 검증을 빼고 null을 허용한 다음 내부에서 !연산자를 이용해서 검증하는게 최선이다.

  • https://github.com/schneidersteve/buckpal-kotlin

Java try-catch block internal

자바의 try-catch 블록이 내부적으로는 OS에서 꽤나 큰 리소스를 요구하는 연산이라고 한다. 따라서 RUST나 최근의 언어에서는 오히려 이를 없애고 예외발생 시 결괏값을 직접 명시하는 추세이다.

  • https://www.infoworld.com/article/2076868/how-the-java-virtual-machine-handles-exceptions.html
  • https://stackoverflow.com/questions/8481907/dealing-with-try-catch-exceptions-in-java-bytecode-stack-height-inconsistent
  • https://blog.jamesdbloom.com/JavaCodeToByteCode_PartTwo.html#try_catch_finally
  • https://www.artima.com/articles/try-finally-clauses-defined-and-demonstrated
  • https://www.javatpoint.com/try-catch-block
  • https://stackoverflow.com/questions/68333290/how-does-exception-handling-work-internally-in-java
  • https://www.programiz.com/java-programming/try-catch
  • https://www.w3schools.com/java/java_try_catch.asp
  • https://www.digitalocean.com/community/tutorials/java-catch-multiple-exceptions-rethrow-exception

Rust vs GO

성능이나 성능의 세부적인 조작에 있어서는 Rust가 좀 더 우세한 것 같다. 대신에 문법적인 내용이나 이해하는 데 있어서 더 어렵다. 성능적인 유리함 때문에 극한의 성능이 중요시되는 디스코드같은 음성채팅 서비스는 Rust로의 전환을 하지않았나 싶다.

  • https://discord.com/blog/why-discord-is-switching-from-go-to-rust
  • https://velog.io/@gtfo/Rust%EB%A5%BC-%EB%B0%B0%EC%9A%B0%EC%9E%90
  • https://www.getclockwise.com/blog/rust-vs-go
  • https://itnext.io/rust-vs-go-cc38b7048181
  • https://www.getclockwise.com/blog/rust-vs-go

Rust에는 매크로라는 기능도 있어서 !기호를 사용하여 자바의 System.out.println처럼 메서드를 호출하는 방식이 아니라, 좀 더 성능이 좋은 무언가를 쓸 수 있다고 한다.

  • https://doc.rust-lang.org/book/ch19-06-macros.html

Jetty vs Netty

  • Jetty는 HTTP 애플리케이션을 작성하기 위한 프레임워크
  • Netty는 TCP/UDP 애플리케이션을 작성하기 위한 프레임워크
  • https://stackoverflow.com/questions/5385407/whats-the-difference-between-jetty-and-netty
  • https://www.linkedin.com/pulse/jetty-vs-netty-siddharth-nawani/?trk=articles_directory

Spring Boot + Netty or Jetty

스프링 부트에는 기본적으로 내장톰캣이 있지만 의존 설정으로 Netty나 Jetty 등 다른 웹 서버를 사용할수도 있다.

  • https://i-hope9.github.io/2020/12/14/SpringBoot-Netty-2-SocketServer.html
  • https://www.baeldung.com/spring-boot-reactor-netty
  • https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/html/howto-embedded-web-servers.html

Spring Boot Redis

스프링 부트에서 레디스 연동..

  • https://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/cache/RedisCacheManager.html
  • https://deveric.tistory.com/98
  • https://www.baeldung.com/spring-boot-redis-cache

Spring Boot: Customize the Jackson ObjectMapper

REST API 연동을 하는데, 스프링 부트에서는 기본적으로 Jackson의 ObjectMapper가 내장되어서 카멜 케이스(camelCase)로 필드명이 설정된다. 그런데 다른 외부의 모듈에 스네이크 케이스(snake_case)로 서빙해야할 때는 어떻게 해야할까?

기본적인 스프링 부트의 동작을 커스터마이징 하기위해서 빈 등록을 한 다음, 뭔가 스프링 빈 라이프 사이클에 끼어들어서 후킹한 다음 해당 로직을 적용시킬 수도 있다.

또는 Spring MVC로 응답하는 모든 필드에 JsonNaming 애너테이션으로 매핑하는 방식이 있다. 이 방법이 가장 파급력도 작고 자연스러운 방법이 아닐까 생각한다.

둘 다 허용해주려면 어떻게 해야하는가? 음.. 이 부분은 직접 처리하기 어려워 보인다. 내부적으로 ObjectMapper가 우선순위가 높은 기준으로 매핑해보고 안되면 다음의 기준으로 넘기던가 해야할텐데, 일부 필드는 camel case이고 다른 부분은 snake case이면 또 예외처리를 해야하니까 나름의 기준이 필요할 것이다.

  • https://www.baeldung.com/spring-boot-customize-jackson-objectmapper
  • https://reflectoring.io/spring-bean-lifecycle/
  • https://www.digitalocean.com/community/tutorials/spring-bean-life-cycle
  • https://www.baeldung.com/spring-boot-customize-jackson-objectmapper
  • https://junho85.pe.kr/1628
  • https://medium.com/@bhanuchaddha/parse-snake-case-json-in-spring-boot-66b42627a791
  • https://stackoverflow.com/questions/10519265/jackson-overcoming-underscores-in-favor-of-camel-case
  • https://www.baeldung.com/jackson-deserialize-snake-to-camel-case
  • https://umbum.dev/1140
  • https://aandi.tistory.com/24

Spring Boot vs Micronaut vs Quarkus

  • https://regupathit.medium.com/quarkus-vs-micronaut-a-deep-comparison-84cae4fea966

Bus factor

  • https://www.lesstif.com/software-engineering/bus-factor-106857476.html

jOOQ

자바 DB 라이브러리라고 하는데, SQL문을 거의 그대로 자바 코드로 옮겨놓은 것처럼 보인다.

  • https://www.lesstif.com/software-engineering/bus-factor-106857476.html

책 추천

  • http://www.yes24.com/Product/Goods/2824034
  • http://www.yes24.com/Product/Goods/108192370
  • https://refactoring.guru/ko/design-patterns/examples

블로그 개선 희망사항

특정 키워드에 대해서 모아서 보고 싶은 경우 -> 태그 기능이나 카테고리 설정 기능이 있으면 좋겠다. 책이나 사이트에 대한 북마크를 관리할 수 있도록 HashMap 같은 구조로 저장되면 좋겠다.