본문 바로가기
TIL WIL

20220630 TIL

by Youngin 2022. 6. 30.

1. @RestController == @Controller + @ResponseBody

 

2. 프론트연동 설정 안해놓으면 서버가 정상적으로 돌아가더라도 white label 창이 뜰 수 있음

 

3.

MySQLNonTransientConnectionException: Too many connections 해결

상황 :

MSA 환경이어서 서비스마다 DB커넥션을 유지하기 때문에 한명당 pool을 6~7개 이상 잡아먹어서 발생

다들 로컬에서 커넥션을 유지시켜놓고 해제하지 않아 커넥션이 많이 잡아먹히게 됨.
베타 DB는 성능이 좋은 서버를 쓰지 않았기 때문에 버티지 못하는 것

spring.datasource.hikari.minimum-idle=2
spring.datasource.hikari.validation-timeout=30000
spring.datasource.hikari.connection-timeout=30000
spring.jpa.hibernate.ddl-auto=update
spring.datasource.hikari.max-lifetime=240000
spring.datasource.hikari.maximum-pool-size=2

추가 참고 : https://lion-king.tistory.com/entry/MySQL-MariaDB-max-connections-Too-many-connections-%EC%98%A4%EB%A5%98-%ED%95%B4%EA%B2%B0

 

4. Timestamped 쓸 때 기본 어플리케이션파일에 @EnableJpaAuditing 를 추가하자

안 그러면 자동생성이 되지 않는다.

 

5. builder를 사용하는 것은 객체생성하는 방법 중 하나이다

@Builder
public Member(String email, String name, int age, Gender gender) {
    this.myServiceEmail = email;
    this.myServiceName = name;
    this.myServiceAge = age;
    this.myServiceGender = gender;
}
Support support = new Support(requestedDto);

이거랑 기능적 차이는 없지만, 좀더 구성 요소들을 바로바로 볼 수 있음

 

6. @RequestMapping

api 주소 설정시 공통되는 부분을 미리 묶어서 정의해놓는데 사용

@RequestMapping("/backend/api/")

@PostMapping("/supports")

이렇게하면 해당 post 요청시에 backend/api/supports 라는 주소로 요청해야 요청이 성공한다.

requestmapping여부를 미리 확인하면, 좀 더 가독성이 높아지는 듯 하다

 

7. APIResponse 객체를 만들어서 모든 API 요청에 대해 해당 타입으로 한 번 감싸서 리턴하도록 할 수 있다.

https://gom20.tistory.com/117?category=1035977 

 

'TIL WIL' 카테고리의 다른 글

WIL  (0) 2022.07.04
220701 TIL  (0) 2022.07.04
20220629 TIL  (0) 2022.06.29
TIL 20220627  (0) 2022.06.27
WIL 10th  (0) 2022.06.27