728x90
전체 글
519

[Spring Boot 2] Spring Security - 간단 인증 구현과 내부 구조

Spring Security를 사용한 로그인(인증) 기능을 구현한다. 간단한 예시로 먼저 구현해볼 것이기 때문에 DB는 사용하지 않는다. Dependency dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' t..

Java & Spring 2024.03.03

SseEmitter를 사용하여 특정 대상에게 메시지(알람) 전송

Dependency 추가 Spring Boot 2 기준으로 다음과 같이 Dependency를 추가해준다. dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' ... testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } Security 설정 Spring Security 설정 부분은 이전에 ..

Java & Spring 2024.03.02

AOP를 적용하여 BindingResult 처리

Spring validation을 사용할 경우 다음과 같이 bindingResult를 받아 처리할 수 있다. @PostMapping public ResponseEntity testMethod( @Valid FormRequest formRequest, BindingResult bindingResult) { ... } 그리고 validation을 수행해야하는 api 요청이 하나 둘씩 추가되면 추가된만큼 bindingResult를 처리하는 코드 또한 추가로 작성될 것이다. 이처럼 boilerplate 코드가 발생하게되면서 비효율적인 코드가 되는 것이다. AOP annotation 정의 annotation을 추가한 method만 bindingResult를 처리할 수 있게 annotation을 정의한다. @Tar..

Java & Spring 2024.03.02

Spring RabbitMQ - publish/subscribe

Docker 먼저 Docker를 설정하여 컨테이너를 생성한다. Dockerfile FROM rabbitmq:latest docker-compose version: '1' services: rabbitmq: container_name: rabbitmq-test build: dockerfile: Dockerfile image: rabbitmq ports: - "15672:15672" - "5672:5672" Dependency spring boot 2 기준으로 dependency를 다음과 같이 추가해준다. implementation 'org.springframework.boot:spring-boot-starter-amqp' implementation 'org.springframework.boot:spring..

Java & Spring 2024.02.28

Spring WebSocket을 사용하여 특정 대상에게 메시지(알람) 전송

Dependency 추가 spring boot 2를 기준으로 다음과 같이 Dependency를 추가해준다. dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation 'org.springframework.boot:spring-boot-starter-security' ... } Security 설정 특정 대상에게 메시지를 전송하려면 그 대상의 ID 또는 unique한 값을 알아야한다. 현재 예시는 authentication을 수행하여 유저의 ID를 사용한다. Princ..

Java & Spring 2024.02.26

1:N관계의 Join Fetch 결과에서 중복 데이터 제거

ERD 간단하게 위와 같은 구조의 DB를 가지고 있다고 했을 때 Article을 조회하면 UserAccount, ArticleComment, ArticleFile 정보가 필요하므로 같이 조회해야한다. 이때 UserAccount, ArticleFile은 1:1관계이기 때문에 조회한 Article 개수대로 결과가 반환되지만 ArticleComment는 1:N 관계로 ArticleComment 개수만큼 Article이 중복되어 결과가 반환된다. 예를 들어 ArticleComment가 100개가 있는 Article을 left join하여 조회한 결과를 보면 다음처럼 100개만큼 Article 데이터가 중복되어 나타난다. select a.id, a.title, ac.id from article a left out..

Java & Spring 2024.02.19

Git과 Slack 연동으로 알림 받기

1. 워크스페이스 생성 2. 알람을 받을 채널 생성 3. GitHub 앱 추가 slack app directory에서 GitHub을 검색하여 추가 또는 앱 추가로 추가 4. GitHub 계정 연결 5. GitHub Repository 연결 6. GitActions 연동 앱 추가 https://api.slack.com/apps GitHub에 Webhook URL 등록 workflows 추가 위처럼 repo에 직접 들어가서 추가하거나 ide 또는 terminal을 사용하여 추가하고 push 한다. name: Slack Notification on: pull_request: branches: - '**' jobs: build: runs-on: ubuntu-latest steps: - name: action-s..

Temp 2024.02.16

[Mac] infer를 사용한 static code analyze

infer는 Meta에서 개발한 정적 분석 tool이다. https://fbinfer.com/ Install https://github.com/facebook/infer/blob/main/INSTALL.md # install dependencies brew install autoconf automake cmake opam pkg-config sqlite gmp mpfr java # Checkout Infer git clone https://github.com/facebook/infer.git cd infer # Compile Infer ./build-infer.sh java # install Infer system-wide... sudo make install Analyze 다음과 같이 command l..

Java & Spring 2024.02.16

프로메테우스와 그라파나를 활용한 Response Time 모니터링

프로메테우스 설치 및 실행 brew install prometheus -> 설치 brew services start prometheus -> 실행 ps -ax | grep prometheus -> prometheus.yml 위치 확인 prometheus.yml에 설정된 호스트 주소로 접속 Spring Dependency 의존성 추가 implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-core' runtimeOnly 'io.micrometer:micrometer-registry-prometheus' properties 설정 management: server: ..

Java & Spring 2024.02.14
728x90