Spring

    [Github Actions] github actions로 Spring Boot secrets 관리 (application.yml)

    [Github Actions] github actions로 Spring Boot secrets 관리 (application.yml)

    gitignore로 DB나 AWS의 민감 정보들을 숨겨놓은 후, github actions를 활용하여 gradle build를 진행할 때 secrets를 활용해서 빌드를 성공하는 방법이다. cloud: aws: s3: bucket: ${S3_BUCKET} credentials: access-key: ${S3_ACCESS_KEY} secret-key: ${S3_SECRET_KEY} region: static: ${S3_REGION} auto: false stack: auto: false 먼저 aws S3 관련 설정을 application.yml에 다음과 같이 넣어두었다. application-private.yml 파일에 민감정보들을 담아두고 gitignore로 깃헙에 업로드되지 않게 하였다. reposit..

    [Spring] Kotlin + Spring boot 프로젝트에 Redis 적용

    build.gradle dependencies { ... implementation 'org.springframework.boot:spring-boot-starter-data-redis' } application.yml spring: redis: host: ${REDIS_HOST} port: ${REDIS_PORT} password: ${REDIS_PASSWORD} 비밀번호를 설정하지 않았다면 password는 빼도 된다 EC2에 도커를 활용하여 redis를 설치해서 ec2의 퍼블릭 ip와 설정한 포트번호를 추가하였다. ** docker에서 redis container 실행하기 sudo docker run -p 6379:6379 --name redis -d redis:latest --requirepass..

    [Spring Boot] Java DateTime Json 입력 시 400 error

    @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date Json에 입력한 날짜를 String으로 인식하여 LocalDate와 연결이 되지 않는다. 컨트롤러에 해당 매핑을 추가하면 정상적으로 데이터를 조회할 수 있다.

    [스프링] Spring messages.properties 한글 인코딩

    [스프링] Spring messages.properties 한글 인코딩

    김영한님 강의를 수강하던 중, messages.properties에 한글을 입력하면 ??로 출력되는 문제가 발생했다. https://www.inflearn.com/questions/277955/%ED%95%9C%EA%B8%80-%EC%9D%B8%EC%BD%94%EB%94%A9-%EA%B4%80%EB%A0%A8-%EC%A7%88%EB%AC%B8%EC%9E%85%EB%8B%88%EB%8B%A4 한글 인코딩 관련 질문입니다. - 인프런 | 질문 & 답변 ms.getMessage('hello', null, null)을 넣고 테스트를 돌렸을 때 아래와 같이 뜨면서 테스트가 실패합니다. Expecting: to be equal to: but was not. org.opentest4... www.inflearn.co..

    [Spring] 스프링 요청 파라미터 - Reqeust Param (required, defaultValue)

    Spring request param @ResponseBody public String requestParamRequired(@RequestParam(required = true) String username, @RequestParam(required = false) Integer age) { log.info("username={}, age={}", username, age); return "ok"; } http://localhost:8080/request-param-required?username=hello → age가 없을 때 파라미터를 int age로 하면 500 에러 → int 형은 primitive type이어서 null값을 가질 수 없음 Integer로 바꿔주면 age는 null이 됨 (아니면..

    [Spring] 로깅 logging

    로깅 로깅 라이브러리 스프링부트 라이브러리를 사용하면 스프링 부트 라이브러리가 함께 포함 (spring-boot-starter-logging) SLF4J: 인터페이스, 구현체-Logback (스프링 부트가 기본으로 제공) 로그 선언 log.trace("trace log={}", name); log.debug("debug log={}", name); log.info("info log={}", name); log.warn("warn log={}", name); log.error("error log={}", name); trace → error로 갈수록 포함 범위가 작아짐 trace: 하위 모든 레벨 포함 error: error만 로그로 출력 log.trace("trace log={}", name); log...

    [intellij/spring] 인텔리제이 spring boot annotation "Cannot read symbol"

    git에서 clone한 후에 자바 버전이 스프링부트와 맞지 않아서 자바 버전을 다시 설정했음에도 스프링 부트의 annotation들을 읽지 못하는 문제가 발생했다. 1. file → invalidate caches → restart 2. java 버전 다시 설정 3. intellij 업데이트 순서대로 해봤더니 인텔리제이 버전을 업데이트하니까 해결되었다. intellij의 시스템 폴더도 삭제해보고, maven update도 해봤는데 인텔리제이 버전 문제였던 것 같다!

    [Spring] 스프링 MyBatis 연동

    MyBatis 1. pom.xml에 의존성 추가 org.apache.commons commons-dbcp2 2.8.0 mysql mysql-connector-java 8.0.22 org.mybatis mybatis 3.5.6 org.mybatis mybatis-spring 2.0.6 org.springframework spring-jdbc ${org.springframework-version} 2. applicationContext.xml dataSource 빈 등록 driverClassName, url, username, password sqlSessionFactory 등록 dataSource 연결 mapperLocations - mapper.xml의 경로 지정 typeAliasesPackage - d..

    [Spring] 스프링 - File Upload, Download

    파일 업로드 / 다운로드 1. pom.xml에 commons-fileupload 추가 commons-fileupload commons-fileupload 1.4 2. servlet-context에 multipartResolver 추가 defaultEncoding = 인코딩 방식 maxUploadSize= 최대 업로드 크기, -1인 경우 무한 3. form 수정 ... method: POST, enctype=”multipart/form-data”로 설정 이미지 파일만 받고싶은 경우 accept="image/*" 4. ProductController @PostMapping("/product/regist") public String regist(Model model, @RequestPart(required =..

    [Spring] 스프링 인터셉터 - Handler Interceptor

    HandlerInterceptor를 통한 요청 가로채기 Controller가 요청을 처리하기 전/후 처리 실제 Business Logic과 분리되어 처리해야 하는 기능을 넣고 싶을 때 유용하다 @Component public class SessionInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSession session = request.getSession(); // 세션에 로그인 정보가 있다면 그대로 진행 if (session.getAt..

출처: https://gmnam.tistory.com/157 [Voyager:티스토리]