Spring

Spring/공부

Spring MongoDB 어노테이션 정리

RDBMS, MongoDBtable, collectionrow, documentcolumn, field @Document: 몽고디비 컬렉션으로 매핑되는 객체임을 선언. 컬랙션의 이름을 매개변수로 부여 할 수 있으며, 별도 지정 없다면 클래스 이름이 컬랙션 이름이 된다.ex) @Document(collection="article") @Id: 문서의 아이디 프로퍼티임을 선언. 일반적으로 String 타입 사용됨@Field("필드 이름"): 모델 객체의 프로퍼티가 매핑되는 몽고디비의 필드 이름을 선언. 어노테이션 생략될 경우 프로퍼티 이름이 그대로 쓰인다.@Indexed: 해당 필드에 인덱스를 생성. 인덱스가 ..

Spring/공부

gradle boot 3.xx QueryDSL 설정

# build.gradledependencies { // query dsl for jpa implementation 'com.querydsl:querydsl-jpa::jakarta' annotationProcessor 'com.querydsl:querydsl-apt::jakarta' annotationProcessor 'jakarta.annotation:jakarta.annotation-api' annotationProcessor 'jakarta.persistence:jakarta.persistence-api'} jpa 쿼리 개발 용 #ymlspring: jpa: show-sql: true properties: hibernate: ..

Spring/공부

스프링 초기 실행 작업을 위한 ApplicationRunner, CommandLineRunner

interface Runner {}@FunctionalInterfacepublic interface ApplicationRunner extends Runner { void run(ApplicationArguments args) throws Exception;}@FunctionalInterfacepublic interface CommandLineRunner extends Runner { void run(String... args) throws Exception;}스프링 빈들이 모두 생성, DI가 끝난 뒤 실행되는 코드를 작성 하고 싶을 때 사용 ex)- 서버 시작 시 초기 데이터 넣기- 캐시 미리 로딩- 외부 API 초기 연결- 관리자 계정 자동 생성- 스케쥴러/MQ 선행 연결 1. ApplicationR..

Spring/공부

스프링 프로퍼티 정리

# application.propertieslogging.level.root = warn # 출력할 로그 파일 경로logging.file.name = ./log/app.log# 로그 백업 시 파일 이름의 패턴(%d는 백업 날짜, %i는 동일한 날짜에 여러 개의 백업 파일이 생성 될 경우 1부터 시작하는 일련번호, 확장자가 gz라면 gzip으로 백업 파일압축)logging.logback.rollingpolicy.file-name-pattern=.log/app.backup.%d{yyyy-MM-dd}.%i.gz# 백업 파일의 보관 일수logging.logback.rollingpolicy.max-history=7# 로그 파일의 크기가 10KB 넘으면 백업logging.logback.rollingpolicy.ma..

Spring/공부

스프링 빈 등록 방법 @Component, @Bean

1. @Component 방식@Componentpublic class TestService {}- 스프링이 실행 시 컴포넌트 스캔으로 클래스 경로를 스캔해서 자동으로 객체 생성 + 빈 등록- 보통 내가 직접 구현한 클래스를 빈 등록 할 때 씀 (Service, Controller, Repository)/** * Indicates a {@link Configuration configuration} class that declares one or more * {@link Bean @Bean} methods and also triggers {@link EnableAutoConfiguration * auto-configuration} and {@link ComponentScan component scanning..

Spring/공부

JPA - Lazy Loading, @Transactional에 관해

@Getter@NoArgsConstructor(access = AccessLevel.PROTECTED)@Entity@Table(name = "users")//@SQLDelete(sql = "UPDATE users SET deleted = true WHERE id = ?")//@Where(clause = "deleted = false")public class User extends BaseTimeEntity implements UserDetails { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "user_id" , unique = true, nullable = false) ..

Spring

StringUtils.isEmpty is deprecated

StringUtils.isEmpty()는 deprecated 되었다고 경고창이 떴다. 대체제로 hasText(),hasLength()를 사용 하면 된다. 나의 경우 hasText를 써서 적용 하니 잘 동작 했다.

Spring/security

권한제어 하는 여러가지 방법

1. @Secured('권한이름') @Operation(summary = "테스트", description = "권한 인가 테스트") @Secured("ROLE_Admin") // 해당 메서드에 대한 권한 설정 @PostMapping("/test") public String test() { return "success"; }2. 여러 권한을 접근 제어 하려면 @PreAuthorize @RestController @RequiredArgsConstructor @RequestMapping("/members") @Tag(name = "유저(멤버)", description = "유저 관련 api 입니다") public class MemberController { // ... @Operation(su..

synclair
'Spring' 카테고리의 글 목록