본문 바로가기

스프링부트11

스프링부트 API JPA 최적화 페치조인, 페이징 default_batch_fetch_size 페치조인, 페이징 1. 페이징 엔티티 조회 * 선호하는 방법 중 하나 @GetMapping("/api/v3-1/orders") public ResponseEntity orderV3_page( @RequestParam(value = "offset", defaultValue = "0") String offset, @RequestParam(value = "limit", defaultValue = "100") String limit ) { // N 만큼 데이터 나옴 List orders = repository.findAllWithMemberDelivery(offset, limit); // ToOne 관계이기 때문에 페이징 가능 List result = orders.stream() .map(o -> new Ord.. 2023. 12. 23.
스프링부트 API JPA 최적화 ToOne 관계 (N+1 문제) , 페치 조인 ToOne 관계 (N+1 문제) , 페치 조인 지연 로딩과 조회 성능 최적화 주문(Order) 내의 ToOne 관계인 member, delivery 지연로딩 조회 Entity @Table(name = "orders") @Getter @Setter public class Order { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "order_id") private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; // = new ProxyMember()를 생성해서(하이버네이트에서) 넣어둔다. // =.. 2023. 12. 19.
Vue 3 쇼핑몰 만들기 - 2 (+ Spring Boot) 기능 추가 장바구니 주문하기 상품 Card.vue {{item.name}} {{ lib.getNumberFormatted(item.price) }}원 {{ lib.getNumberFormatted(item.price - (item.price * item.discountPer / 100)) }} {{ item.discountPer }}% 스프링부트 컨트롤러 @PostMapping("/api/cart/items/{itemId}") public ResponseEntity pushCartItem(@PathVariable int itemId, @CookieValue(value = "token", required = false) String token){ isTokenValid(token); int memberId.. 2023. 4. 20.
Spring Cloud (MSA) - 모니터링 (Actuator, Prometheus, Grafana) 개요 배포를 한 뒤에 내가 내가 배포한 서버가 잘 동작하는지 어떻게 동작하고 있는지 서버의 상태를 확인할 수가 없었습니다. 그래서 모니터링하는 기술들이 있었는데 적용해본 기술들은 다음과 같습니다,. Spring Actuator Prometheus Grafana 그라파나를 사용하기 위해서는 프로메테우스의 정보가 필요하고 프로메테우스를 사용하기 위해서는 /actuator/prometheus 와 같이 연결이 필요했습니다. 그래서 Spring Actuator, Prometheus, Grafana 순으로 적용시켜보았습니다. 환경 Win11 Spring boot 2.7.8 Docker Engine v20.10.21 Spring Actuator implementation 'org.springframework.boot.. 2023. 2. 16.
Spring Cloud (MSA) - Resilience4j @Retry @CircuitBreaker(서킷브레이커) Resilience4j 앞의 서비스가 다운되거나 느릴 때 전체 chain에 영향을 끼친다. -> 만약 그럴때 fallback 반환 -> 부하 감소를 위한 CIrcuit Breaker pattern을 구현 -> 다시 요청 -> 속도 제한 ∴ Resilience4j currency-exchange-service 프로젝트 의존성 추가 org.springframework.boot spring-boot-starter-aop io.github.resilience4j resilience4j-spring-boot2 package com.javapp.microservices.currencyexchangeservice.controller; import io.github.resilience4j.retry.annotation.. 2022. 12. 6.
Spring Cloud (MSA) API Gateway - 경로탐색(Exploring Routes), Logging Filter 이전 포스팅 : 로드밸런서 Spring Cloud Gateway 사용 Simple, yet effective way to route to APIs Provide cross cutting concerns: Security Monitoring/metrics Built on top of Spring WebFlux (Reactive Approach) Features: Match routes on any request attribute Define Predicates and Filters Integrates with Spring Cloud Discovery Client (Load Balancing) Path Rewriting Eureka http://localhost:8761 Setting up Spring Cl.. 2022. 12. 3.
Spring Cloud (MSA) - Feign 다른 서버 값 가져오기 Feign 다른 서버에서 실행된 결과를 가져옴 Currency Exchange Microservice CurrencyExchange @NoArgsConstructor @Getter @Setter @Entity public class CurrencyExchange { @Id private Long id; @Column(name = "currency_from") private String from; @Column(name = "currency_to") private String to; private BigDecimal conversionMultiple; private String environment; } CurrencyExchangeController @RestController public class C.. 2022. 11. 26.
[프로젝트] Spring Boot + JSP를 이용한 함께 부산 여행할 사람을 구하는 웹 사이트-4-JSP 페이지 JSP를 이용한 화면 구성과 처리 메인 홈 http://localhost:8888/ 카드 형식으로 TourArea 출력 mainHome.jsp ${tourareaDTO.title } ${tourareaDTO.contents_name } Tour c:forEach : c태그를 통해 반복 값 표현 : ${ .. } 그전에 JSP 에서 DTO 객체를 사용하고 싶다면 @Controller 클래스에서 해당 페이지가 맵핑된 메소드에 Model 객체를 이용해 담아놓아야된다. model.addAttribute("tourareaDTOs",tourareaDTOs); TourReviewDTO @Data @NoArgsConstructor @AllArgsConstructor public class TourReviewDTO { .. 2022. 7. 31.
Spring boot - blog application (REST API) : Validation @Valid 스프링 부트에서 유효성 검사를 해보려고 합니다. Create, Update Post REST API 요청에 대해 유효성 검사 dependency 추가 org.springframework.boot spring-boot-starter-validation 2.7.0 PostDto 에 애노테이션 추가 package com.springboot.blog.payload; @Data public class PostDto { private long id; @NotEmpty @Size(min =2, message="Post title should have at least 2 characters") private String title; @NotEmpty @Size(min= 10, message="Post descripti.. 2022. 7. 6.
Spring boot - blog application (REST API) : Pagination and Sorting Support 기존 포스트 리스트에서 페이지네이션을 적용시키려고 합니다. 페이지네이션을 사용자가 쉽게 설정할 수 있도록 따로 클래스 작성 AppConstants package com.springboot.blog.utils; public class AppConstants { // page elements public static final String DEFAULT_PAGE_NUMBER = "0"; public static final String DEFAULT_PAGE_SIZE= "10"; public static final String DEFAULT_SORT_BY= "id"; public static final String DEFAULT_SORT_DIRECTION= "ASC"; } payload PostResponse.. 2022. 6. 30.
Spring boot - blog application (REST API) : Post CRUD REST API 를 통해 게시물을 CRUD - Create(생성), Read(읽기), Update(갱신), Delete(삭제) 적용 패키지 구조 application.properties spring.datasource.dbcp2.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/myblog?userSSL=false&serverTimezone=Asia/Seoul&characterEncoding=UTF-8 spring.datasource.username = root spring.datasource.password = root # hibernate properties spring.jpa.prop.. 2022. 6. 29.