spring boot 16

Spring Boot와 HMAC을 활용한 데이터 서명 및 검증 구현

개요애플리케이션에서 데이터를 보호하고 무결성을 보장하기 위해 HMAC(Hash-based Message Authentication Code)를 활용할 수 있습니다. 본 글에서는 Spring Boot를 이용한 HMAC 기반의 전자서명 및 검증 API를 구현하는 방법을 설명합니다. HMAC 이란?HMAC은 키를 사용하여 데이터를 해싱하여 서명을 생성하는 방법입니다. HMAC을 사용하면 데이터가 변경되지 않았음을 검증할 수 있으며, 공유된 비밀 키를 통해 보안성을 유지할 수 있습니다.HMAC-SHA256 알고리즘을 사용하여 JSON 데이터를 서명하고 검증하는 API를 구현합니다. HMAC 서명 및 검증 API 구현import org.springframework.web.bind.annotation.*;impor..

프로그래밍 2025.03.19

스프링에서 빈(Bean)을 등록하는 두가지 방법

1. 어노테이션 기반 빈 등록스프링이 제공하는 특정 어노테이션을 클래스에 선언하여 빈으로 등록하는 방식입니다.대표적인 어노테이션:@Component: 일반적인 컴포넌트로 빈 등록.@Controller: MVC 패턴에서 컨트롤러 역할을 하는 클래스에 사용.@Service: 비즈니스 로직을 처리하는 서비스 레이어 클래스에 사용.@Repository: 데이터 접근을 담당하는 DAO 클래스에 사용.어노테이션 사용 시 스프링이 **컴포넌트 스캔(Component Scan)**을 통해 해당 클래스를 찾아 빈으로 등록합니다.예제@Componentpublic class MyComponent { public void doSomething() { System.out.println("Component 실행..

[vscode] java17 + springboot3.1 + mysql8 + mybatis3.0 + themleaf

오랜만에 java 프로젝트 생성해봅니다.이번엔 intelliJ IDEA 대신 vscode 로 셋팅해 봅니다.Mysql 테이블 생성 및 데이터 insertCREATE TABLE users ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL);INSERT INTO users (name, email) VALUES('John Doe', 'john.doe@example.com'),('Jane Smith', 'jane.smith@example.com'),('Mike Johnson', 'mike.johnson@example.com'),('Emily Brown', 'emily.brown@e..

[spring boot JPA] object references an unsaved transient instance - save the transient instance before flushing 오류 원인

"object references an unsaved transient instance - save the transient instance before flushing" 오류는 Hibernate 또는 JPA에서 발생하는 오류로, 영속성 컨텍스트에 저장되지 않은(transient) 엔티티를 다른 엔티티가 참조하고 있을 때 발생합니다. 이 경우, 영속성 컨텍스트는 참조한 엔티티를 올바르게 관리하지 못하므로 오류가 발생합니다. 이 오류를 해결하기 위해 다음을 확인하십시오: 연관 엔티티 저장: 먼저 연관 엔티티(Team)를 저장한 후, 메인 엔티티(Members)에 연관 엔티티를 설정하세요. 영속성 컨텍스트는 참조된 엔티티가 영속 상태로 저장되어 있어야 합니다. 원본 Members members = new M..

spring boot 와 JPA + mysql 사용한 두개 테이블 조인 Insert

프로젝트 구조 build.gradle buildscript { repositories { mavenCentral() } dependencies { classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.10" } } plugins { id 'java' id 'war' id 'org.springframework.boot' version '2.7.14' id 'io.spring.dependency-management' version '1.1.2' id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10' // Querydsl 플러그인 추가 } group = 'com.naya' version = '0..

IntelliJ 이용하여 스프링 부트 + JPA + Mysql 간단한 예제

JAVA 11 사용 build.gradle plugins { id 'java' id 'war' id 'org.springframework.boot' version '2.7.14' id 'io.spring.dependency-management' version '1.1.2' } group = 'com.naya' version = '0.0.1-SNAPSHOT' java { sourceCompatibility = '11' } configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring..

intelliJ Springboot + MyBatis + MySQL 셋팅 및 연동(1)

목적 : 쇼핑몰 만들기 위한 기본적인 셋팅을 해본다. java 17 버전 사용 -> java 11 로 변경 java 11 로 변경 Selected Dependencies 항목을 모두 체크 해준다. build.gradle java 11 plugins { id 'java' id 'war' id 'org.springframework.boot' version '2.7.14' id 'io.spring.dependency-management' version '1.1.2' } group = 'com.naya' version = '0.0.1-SNAPSHOT' java { sourceCompatibility = '11' } configurations { compileOnly { extendsFrom annotationP..

[java] 인텔리제이 스프링부트 + 웹소켓 연결방법

Lombok 추가 프로젝트구조 build.gradle 스프링부트 버전을 2.6.1 로 해준다. sourceCompatibility 을 11 로 해준다. plugins { id 'java' id 'war' id 'org.springframework.boot' version '2.6.1' id 'io.spring.dependency-management' version '1.1.2' } group = 'com.example' version = '0.0.1-SNAPSHOT' java { sourceCompatibility = '11' } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boo..

spring boot cron 같은 스케쥴러 사용하기

스케쥴링은 일련의 반복되는 행위를 자동으로 간편하게 작성할수 있다. 예를들면 리눅스 시스템의 cron 처럼. 스케쥴 기능 켜기 자바 설정에서 @EnableScheduling 추가하면 스케쥴 기능을 사용할수 있다. main class 에 추가하자. @SpringBootApplication @EnableScheduling public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } 스케쥴 구현 @Scheduled 어노테이션을 사용하면 사용가능하며 실행주기는 cron, fixedDelay, fixedRate 라는 세개의 속성으로 지정할 수 있다..

spring boot application.properties 운영/개발 설정하기

목적 자동 배포시 운영서버 / 개발서버 각각 DB 설정 할수 있도록 하기 위해서... 설정은 아래와 같이 2가지 방법으로 설정한다. spring boot - application.properties 설정 tomcat - catalina.properties 설정 . spring boot 설정 방법 sprint boot 에서 설정 파일 이름은 아래와 같이 한다. 운영 : application.properties 개발 : application-dev.properties .tomcat 설정 방법 톰캣 설정은 아래와 같이 3가지 방법이 존재한다. 1. web.xml - active-profile 설정 spring.profiles.active prod 2. catalina.sh 설정 JAVA_OPTS="$JAVA_..