Spring Boot 14

[Spring Boot] 빌드 실패 (Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.2.3.)

* What went wrong: A problem occurred configuring root project 'GooJob'. > Could not resolve all files for configuration ':classpath'. > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.2.3. Required by: project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.2.3 > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.2.3 was foun..

Spring Boot 2024.03.12

[Spring Boot] CORS Configuration 설정하기

CORS 설정하는 방법에는 여러가지가 있는데, 서버에서 설정하는 법과 클라이언트에서 설정하는 법 중 서버에서 설정하는 게 표준이라고 한다. 서버에서 설정하는 방법 중 내가 선호하는 CORS 설정법은 Configuration 설정 파일을 만드는 것이다. 서버 url은 localhost:8080 클라이언트 url은 localhost:3000 이라고 가정한다. application.yml cors: allow: origins: http://localhost:3000 다음과 같이 cors 설정해줄 클라이언트 url을 적어준다. 꼭 cors.allow.origins 로 안해줘도 된다. Configuration 파일 생성 @Configuration public class WebConfig implements Web..

Spring Boot 2023.06.23

[Spring Boot] RequestMapping VS PostMapping/GetMapping

스프링 controller를 작성하려고 구글링하다보면 메소드에 어노테이션을 붙이는데 어떤건 RequestMapping을 붙이고 어떤건 PostMapping이나 GetMapping을 붙이는 걸 볼 수 있다. @RequestMapping(value = "/post", method = RequestMethod.POST) @RequestMapping(value = "/get", method = RequestMethod.GET) 이 코드가 각각 @PostMapping("/post") @GetMapping("/get") 와 동일한 코드이다. 개인적으로 간결하고 메소드를 구분하기 쉬워서 postmapping과 getmapping을 더 선호한다.

Spring Boot 2023.03.23

[JPA] Persistable 인터페이스

회원가입 개발하다가 같은 회원정보를 입력해서 save() 메서드를 사용했는데도 에러가 나지 않아 보니까 insert 되지 않고 update가 되는 것을 볼 수 있었다. 먼저 맨 처음 엔티티를 생성할때는 insert가 된다. 그런데 아래 로그를 보면 insert 전에 select가 되는 것을 볼 수 있다. @Id를 지정한 컬럼은 똑같이 하고 나머지를 다르게 입력하고 save() 메소드를 실행시키면 로그가 길지만 자세히 보면 update 하기전에 select를 한 번 더 하는 것을 볼 수 있다. 아예 같은 정보를 입력하면 select만 한다. 이렇게 insert, update 할 때 마다 select를 하는 것은 매우 비효율 적이다. https://kdhyo98.tistory.com/63

Spring Boot 2022.11.22

[Spring Boot] 개발환경 설정 -(6) profile별 로그 설정하기(hibernate 등)

회사에서 System.out.println 보다 debug 쓰는게 너무 편리하고개발서버나 운영서버에서 로그를 볼 수 있기 때문에미루던 로그 설정을 해보려고 한다. https://awse2050.tistory.com/72https://goddaehee.tistory.com/206 위 블로그들 설명이 아주 자세하다. https://zzang9ha.tistory.com/399이 블로그는 hibernate 로그 설명이 잘 되어있다. yml 으로도 설정 할 수 있지만 logback-spring.xml을 생성해서 설정하겠다. 결론적으로는 어떤 것을 사용해도 아무 문제가 없고, 기본적인 구조는 비슷하기 때문에 편한 것을 사용하면 되겠다. 개인적으로는 yml을 사용하는 것이 더 구조를 파악하기 쉽고, 중복되는 코드가 ..

Spring Boot 2022.11.01

[Spring Boot] 개발환경 설정 -(5) mySQL JPA 연동하기-②

지난 포스팅에서 데이터베이스와 사용자, 테이블을 만들었다. 이번 포스팅에서는 spring boot 설정과 생성한 테이블에서 데이터를 조회하고 추가해볼 것이다. 1. 프로젝트 설정 (1) Build.Gradle dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-rest' implementation 'org.springframework.boot:spring-boot-starter-web' annotationProcessor 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:..

Spring Boot 2022.06.30

[Spring Boot] 개발환경 설정 -(5) mySQL JPA 연동하기-①

이번 포스팅에서는 mysql설치, dbeaver 연결하고, 테이블 생성까지 해보겠다. 회사에서 여러 프로젝트를 진행했는데 전부 dbeaver를 사용해서 dbeaver로 선택하였다. 1. mySQL 설치 https://dev.mysql.com/downloads/file/?id=511553 MySQL :: Begin Your Download The world's most popular open source database Contact MySQL | Login | Register dev.mysql.com 여기서 아래 No thanks, just start my download. 클릭 2. DataBase 생성 1) 관리자 계정 root로 접속 명령프롬프트를 켜서 mysql -uroot -p 비밀번호 입력 2..

Spring Boot 2022.06.30

[Spring Boot] 개발환경 설정 -(4) 응답 객체 생성하기

컨트롤러를 작성할 때 일일이 응답코드를 설정해주고, ResponseEnity를 리턴해줘야 하는게 번거롭다. 회사에서는 컨트롤러에서 공통으로 쓸 수 있는 클래스를 만들어 상속해서 쓰고 있다. 코딩할 때 공통되는 부분을 최소화 하지 않으면 너무 찝찝해서 최대한 공통되는 코드들은 모아두려고 한다. 이번 포스팅에서는 내가 편하자고 만든 코드를 정리해두었다. ResponseEntity 생성 @Data public class ResponseEntity{ private int code; private String message; private T data; public ResponseEntity(int code, String message, T data) { this.code = code; this.message =..

Spring Boot 2022.06.02