728x90 백엔드145 springboot 멀티 모듈 프로젝트에서 다른 모듈의 빈을 찾지 못할 때 문제 상황 Spring boot 멀티 모듈 프로젝트에서 다른 모듈의 빈을 찾지 못하는 상황. 두 모듈의 group 이 다름 Ex) A 모듈에서 생성한 a bean을 B 모듈 안에서 주입받고 싶음 A 모듈의 group id: com.example.a B 모듈의 group id: com.example.b 발생 에러 생성자 주입 시 argument를 찾을 수 없다는 에러 발생 원인 및 해결 방법 원인은 두 모듈의 group id가 달라서 그런 것..! (정확히는 패키지가!) 기본적으로는 @SpringBootApplication 애노테이션이 붙은 클래스가 위치하는 곳이 basePackage로 설정되어 해당 패키지 하위 패키지의 컴포넌트를 가져옴 하지만 위 예시처럼 패키지가 다른 경우 별도로 컴포넌트 스캔을 하고.. 2023. 1. 9. springboot multimodule ❗️ 멀티 모듈 프로젝트가 필요한 이유 예를 들어서 회원 프로그램을 개발한다고 했을 때 여러 개의 서버가 필요하다. ① batch 서버 ② API 서버 등등 하지만 해당 서버들을 단일 프로젝트로 만들게 되면 다음과 같은 문제가 생긴다. 첫번째, 공통적으로 처리해야하는 코드의 처리 : 아예 분리되어 있는 프로젝트이다 보니 공통되는 코드들은 각 프로젝트에 복붙해서 사용할 수 밖에 없고, 한 파일의 코드가 수정되는 경우 다른 프로젝트의 코드도 수정해줘야 한다. 두번째, 접근성 문제 : 프로젝트 수에 따라 IDE 를 실행시켜야 하고 ,, 프로젝트 수가 많아지면 많아 질 수록 개발하는데 어려움이 동반 될 수 밖에 없다. 이런 문제를 해결하기 위해선 멀티 모듈 프로젝트를 사용하면 된다. ❓ 멀티 모듈 프로젝트의 구.. 2023. 1. 1. spring 외부 경로 매핑 Spring boot에서 외부 경로 매핑하기 import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { regist.. 2022. 8. 11. spring static 경로 404 SwaggerConfig에 추가된 @EnableWebMvc 어노테이션이 원인이었다. 해당 어노테이션 사용시 따로 추가해줘야한다 package com.zeroback.aboutme.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframewo.. 2022. 8. 10. spring responsebody json 필드명 변경하기 memberId -> member_id 로 변경 public class LoginResultDto { @JsonProperty("member_id") Long memberId; String email; } 2022. 8. 2. springboot 파일업로드 프론트에서 MulitpartFormdata로 전송시에도 마찬가지로 추가 form data 컨트롤러 파라미터로 받을 수 있다. @PostMapping("/add_content") public ResponseEntity addContent(Integer content_board_idx, Integer content_writer_idx, String content_subject, String content_text, MultipartFile content_image) throws IOException { if(content_image==null || content_image.isEmpty()){ mainService.createContent(content_board_idx, content_writer_idx,.. 2022. 7. 1. springboot h2 인메모리 모드 설정 SpringBoot에서 H2 DB를 사용하는 방법을 알아보도록 하겠습니다. 1. H2 DB란 역시 우선은, H2 DB가 무엇인지부터 간단히 알아보는게 좋을것 같습니다. H2 란? H2DB는 JAVA기반의 RDBMS입니다. 특징 별도의 설치과정이 없고, 저용량에 가볍고 빠르고 JDBC를 지원합니다. 따라서 개발 및 테스트용으로 많이 사용됩니다. Mode Server mode는 다른 RDBMS처럼 데이터를 실제로 저장함으로써, 다른 사용자들이 접속할 수 있으며, server와 API등에서 접속할 필요성이 있을때 사용합니다. Embedded mode는 JDBC를 사용해 동일한 JVM에서 데이터베이스를 엽니다. 가장 빠르고 쉬운 연결모드이지만, 단 하나의 JVM에서만 데이터베이스를 열수 있기 때문에 테스트용 및.. 2022. 6. 30. jpa @GeneratedValue 기본키 매핑 어노테이션 @Id에 대하여 직접 할당할 땐 @Id만 사용하고, @Id가 선언된 필드에 기본키 값을 자동으로 할당할 때 @GeneratedValue 사용 자동생성은 객체 생성 뒤 직접 코드로 setId()안해줘도 JPA가 알아서 값을 id에 넣어준다는 것이다. @GeneratedValue 전략 (사용예 : @GeneratedValue(starategy = GenerationType.IDENTITY) IDENTITY 전략의 특징 - 기본키 생성을 데이터베이스에 위임하고 주로 MySQL, SQL Server, DB2에서 사용 - 예를 들자면 MySQL을 사용한다면 auto_increment로 지정해서 DDL을 만든다. 1차 캐시에는 @Id와 @Entity로 지정한 것들이 들어간다. 그런데 기본키의.. 2022. 4. 16. spring rabbitMQ 사용 https://www.cloudamqp.com/ CloudAMQP - RabbitMQ as a Service CloudAMQP - industry leading RabbitMQ as a service Start your managed cluster today. CloudAMQP is 100% free to try. www.cloudamqp.com 클라우드 rabbitMQ 사용 해당 port 1883 사용하면 안됨 디폴트 port 사용 application.yml 설정 Cloud rabbitMQ 사용하면 vhost 해줘야하고 default port는 5672 rabbitmq: host: dingo.rmq.cloudamqp.com username: ulnwlrwi password: 1-xzf7tfUz4szU.. 2022. 4. 16. 포트 죽이기 https://7942yongdae.tistory.com/35 Error - Port 8080 was already in use Port 8080 was already in use 에러와 원인과 해결 방법 메시지 *************************** APPLICATION FAILED TO START *************************** Description: Web server failed to start. Port 8080 was.. 7942yongdae.tistory.com netstat -ano | findstr 8080 taskkill /F /pid [process_id] taskkill /pid 13984 /f 2022. 4. 13. Spring Gradle 빌드 (인텔리제이 방법 포함) 우측 Graddle -> 프로젝트 -> Tasks -> build -> build 클릭 [터미널로 빌드] gradlew 유닉스용 실행 스크립트이다. > gradle build 위와 같이 하면 로컬에 설치된 gradle을 사용. 이 경우에 Java나 Gradle이 설치되어 있어야하고, 새로받은 프로젝트의 Gradle 버전과 로컬에 설치된 Gradle 버전이 호환되지 않으면 문제가 발생할 수 있다. > ./gradlew build 위와 같이 하면 Gradle Wrapper를 사용해서 위에서 언급한 문제가 발생하지 않는다. 참고 https://jobc.tistory.com/202 Gradle & Build 그리고 IntelliJ의 Build gradle을 알아보기 전에 컴파일, 빌드의 개념을 알아보자 컴파일과.. 2022. 4. 10. 타임리프 문자열 조합 https://blog.leocat.kr/notes/2018/11/21/thymeleaf-string-concatenation [Thymeleaf] 문자열 조합(합치기) (까먹을까봐 기록차) blog.leocat.kr 2022. 4. 5. 스프링부트 타임리프 라이브 reload https://easybrother0103.tistory.com/62 [Spring Boot] 인텔리제이 Live Reload 설정 템플릿엔진이나, js css등 수정이 잦은 것들을 매번 새로 빌드 하는 것은 매로 번거로운 일이다. SpringBoot Devtools를 통해 새로고침 만으로 resources 밑의 파일들의 실시간 반영을 할 수 있다. 1. Gradle c easybrother0103.tistory.com 2021.2 버전부터 Registry가 아니라 Advacned Settings에서 설정한다고 한다! Registry에서 compiler.automake.allow.when.app.running을 계속 찾다가.. 없어서 기록한다 Setting > Advanced Settings Allow .. 2022. 4. 5. SpringBoot Eureka 서버 설정 설정 build.gradle dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' implementation 'com.sun.jersey.contribs:jersey-apache-client4:1.19.4' testImplementation 'org.springframework.boot:spring-boot-starter-test' } 설정 @EableEurekaServer 설정 application.yml server: port: 8761 eureka: instance: hostname: localhost client: # 해당 두 속서은 유레카와 성호작용하는 방법을 알려주기 .. 2022. 3. 25. 헤로쿠 간단하게 스프링부트 배포 프로젝트 루트 경로에 Procfile, system.properties 파일 생성 설정 파일 작성 빌드 작성 2022. 3. 22. 스프링 시큐리티 OAuth 2.0 https://loosie.tistory.com/300 [Spring] 스프링으로 OAuth2 로그인 구현하기1 - 구글 스프링 시큐리티와 스프링 시큐리티 OAuth2 클라이언트 많은 서비스에서 로그인 기능을 id/password 방식 보다는 써드파티 방식으로 구글, 네이버과 같은 소셜 로그인 기능을 사용한다. 이는 서비스 loosie.tistory.com 참고 그대로 따라 했는데 Thread 에러남 (HttpSession) 빈 등록 후 해결 @Bean public RequestContextListener requestContextListener(){ return new RequestContextListener(); } 2022. 3. 17. 스프링 Rest Template RestTemplate restTemplate = new RestTemplate(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("myheader",token); HttpEntity request = new HttpEntity(payload, httpHeaders); ResponseEntity response = restTemplate.postForEntity(dppURI + "/api/pay/full", request, String.class); return response; 2022. 3. 16. QueryDsl, data jpa 하나의 레포지토리 사용 클래스, 인터페이스 구조 최종 사용하는 레포지토리 (MemberDataRepository) import java.util.Optional; @EnableJpaRepositories /** * 실제 사용하는 리포지토리 * 단순한 CRUD 쿼리는 여기서 작성 */ public interface MemberDataRepository extends JpaRepository, MemberCustomRepository { Member findMemberByEmail(String email); } MemberCustomRepository import java.util.List; @Repository //커스텀 인터페이스 쿼리 작성 public interface MemberCustomRepository { Long e.. 2022. 3. 10. Spring Swagger에서 Pageable 사용 Swagger 에서 Pageable 이용하기 @RequestMapping("/stores") @Api(tags = "store") @RestController public class StoreController { @ApiOperation(value = "메뉴 조회 with paging", notes="store의 id를 이용하여 가맹점의 메뉴를 페이징 처리하여 조회합니다.") @GetMapping(value="/{storeId}/menus") public Map findAllMenuByMenuId(@ApiParam(name="storeId", value="store 테이블 id", required=true) @PathVariable("storeId") long storeId, @PageableDefau.. 2022. 3. 7. Spring Data Jpa repository 통합 @Repsository 어노테이션 안 붙여줘도 빈 등록한다. 2022. 2. 23. InitDB 하는 법 package com.danal.chatting.util; import com.danal.chatting.Role.Role; import com.danal.chatting.entity.Authority; import com.danal.chatting.entity.member.Member; import com.danal.chatting.member.service.MemberService; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; import javax.annotation.. 2022. 2. 22. swagger 파라미터 안보이게 하기 SwaggerConfig.java 파일 설정 2022. 1. 21. Spring HTTPS 설정 인증서 생성 keytool -genkeypair -alias ssafy -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore ssafy.p12 -validity 3650 keytool -export -alias ssafy -keystore ssafy.p12 -rfc -file ssafy.cer keytool -import -alias ssafy -file ssafy.cer -keystore ssafy.ts 모든 패스워드 설정을 123456으로 해줌 server: port: 8443 ssl: enabled: true key-store-type: PKCS12 key-store: classpath:keystore/ssafy.p12 key-store-password: .. 2022. 1. 18. JPA Auditing으로 생성일/수정일 자동화하기 현재 진행중인 프로젝트에서 해당 데이터의 생성시간과 수정시간을 관리해야 할 부분이 있었습니다. 예를 들어, 주문 도메인에서 주문한 시간과 주문 내용을 수정한 시간이 필요했습니다. 그리고 결제 도메인에서는 결제 요청한 시간과 결제 내용을 수정하는 시간이 필요했습니다. 현재 개발 초기 단계이지만 벌써 두 곳에서 생성시간/수정시간이 필요했습니다. 언제 만들어졌는지, 언제 수정되었는지 등은 차후 더 필요해질 것이라 생각 생각했습니다. 여기저기 찾아보다가 책에 해당 내용이 있었습니다. 이제 그 내용을 읽고 적용한 것을 같이 공유하고자 합니다. JPA Auditing으로 생성시간/수정시간 자동화하기 보통 엔티티는 해당 데이터의 생성시간과 수정시간을 포함합니다. 그렇다 보니 매번 DB에 insert하기 전, upda.. 2021. 12. 29. spring security WebIgnore @Override public void configure(WebSecurity web) throws Exception { web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations()); } 2021. 12. 3. spring security user생성 inMemory 방식 user 생성 package io.security.corespringsecurity.security.configs; import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecur.. 2021. 12. 3. spring security 필터 다중 설정 @Order로 순서 설정 package io.security.basicsecurity; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configur.. 2021. 12. 2. spring security csrfFilter 2021. 12. 2. spring security 예외처리 package io.security.basicsecurity; import org.springframework.context.annotation.Configuration; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.anno.. 2021. 12. 2. spring security 인가 antMatcher(경로) 생략하면 모든경로 권한 확인한다. 2021. 12. 1. 이전 1 2 3 4 5 다음 728x90