본문 바로가기

Spring Boot

(6)
[JPA] Persistence Context(영속성 컨텍스트) 해당 내용은 자바 ORM 표준 JPA 프로그래밍의 내용을 정리 Persistence Context 영속성 컨텍스트(Persistence Context)는 엔티티를 영구 저장하는 환경이라는 뜻 엔티티 생명주기 Entity에는 아래와 같은 4가지의 상태가 존재한다. 1. 비영속(new/transient): 영속성 컨텍스트와 전혀 관계가 없는 상태 2. 영속(managed): 영속성 컨텍스트에 저장된 상태 3. 준영속(detached): 영속성 컨텍스트에 저장되었다가 분리된 상태 4. 삭제(removed): 삭제된 상태 비영속 Member member = new Member(); member.setId("member1"); member.setUsername("회원1"); 영속 em.persist(member)..
Spring Boot Test 하기 (1) (모든 전체 코드는 github에 있습니다. ) Spring boot에서는 다양한 어노테이션 등을 이용해서 테스트를 쉽게 할 수 있도록 도와줍니다. 첫번째 포스팅에서는 Spring 기반의 Application 어떻게 이루어져있고 간단한 Rest API 를 만들어 보겠습니다. Overview Spring기반의 RESTFul Web Service는 아래와 같이 표현될 수 있습니다.(HandlerMapping 등은 생략) Spring layer (출처: https://terasolunaorg.github.io/guideline/5.0.1.RELEASE/en/ArchitectureInDetail/REST.html) (1) : User -> WebService로 HTTP POST 요청(Create) (2) : J..
Spring Security + OAuth2(JDBC) + Swagger 서버 구축하기 전체 내용는 github 에서 확인할 수 있습니다 (스타는 사랑입니다) Spring security + OAuth2(JDBC) + Swagger를 모두 설명하기 보다는 구현에 초점을 두겠습니다. 또한 UserDetailService등의 구현 설명은 생략 하겠습니다. Index 의존성 추가 스프링 관련 설정 JDBC 기반 OAuth2 프로젝트 실행 테스트(SWAGGER-UI) 테스트(JUNIT) 의존성 추가 Security, OAuth2, Swagger 관련 의존성 추가 org.springframework.boot:spring-boot-starter-security org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2...
Springboot의 Auto configuration 살펴보기 Springboot의 Auto configuration을 살펴보고 AcitveMQ, RabbitMQ, Kafka에 대해 설정 값에 따른 Auto configuration 활성화를 살펴보겠습니다. 모든 예제는 Github에 있습니다. 스타는 사랑입니다. [ActiveMQ,RabbitMQ,KAFKA] 설정으로 Springboot의 Auto configuration 살펴보기 스프링부트에 "org.springframework.boot:spring-boot-starter-activemq"와 같은 의존성을 추가하고 실행하면 아래와 같이 activemq 관련 빈이 자동으로 생성된 것을 확인할 수 있습니다. main class public class RpcQueueApplication { public static vo..
[Heartbeat] Heartbeat로 서버 헬스체크하기 (Spring boot + Slack Web Hooks + Bot) 모든 소스코드는 Github에 있습니다. (스타는 사랑입니다) Index example heartbeat java agent Event bus(guava event bus) Slack WebHooks, Bot Example 서버 상태가 변하면 WebHooks로 알림 !command로 서버 상태 체크하기 Heartbeat (1) Init state --> (heart beat) --> Healthy state (2) Healthy state --> (heart beat lost) --> Heartbeat lost state (3) Heartbeat lost state --> (heart beat) --> Healthy state 설치 된 Agent에서 각각 Server로 heartbeat를 보냄 2-1) ..
Spring async + stomp websocket 랜덤 채팅 구현 예제 Spring boot + Async + Stomp Websocket을 이용한 랜덤 채팅 구현 예제 > 데모 - server : spring boot, stomp websocket - client : bootstrap, jquery, handlebars, sockjs 채팅 요청 ~ 채팅 형성까지는 비동기로 대기하고 있고, 채팅방이 형성되면 websocket으로 메시지를 주고받는 식으로 간단하게 구현해봤습니다.간단한 로직은 아래와 같습니다 1. 채팅 요청 1. 채팅 요청 (Async : DeferredResult로 응답)2. 유저 등록 (대기 큐에 등록)3. 채팅 가능 체크 3-1) 대기 큐에 2명 이상=> UUID로 채팅방 이름 생성 + Success (+ 채팅방 이름 포함) => UUID로 subscri..