본문 바로가기

분류 전체보기130

Spring validation 과정 중, properties에서 지정한 message 가 출력되지 않음. - 타임리프, 스프링 오류 문제 상황. 오류 메시지를 properties 파일을 이용해 직접 작성하려고 한다. 그러나 옳바르게 문구가 나오지 않고 기본 오류 문구만 출력된다. test 환경에서 MessageSource 를 주입받아 확인해보면 errors.properties 파일 내부의 문구가 옳바르게 MessageSource 빈에 등록된건 확인이 가능하다. DTO @Data @AllArgsConstructor public class MemberJoinForm { @NotBlank private String id; @NotBlank private String pw; @NotBlank @Size(min = 2, max = 5) private String name; @Size(min = 4, max = 15) private String.. 2024. 2. 19.
~~~ because "this.redisTemplate" is null - 스프링 REDIS 테스트 오류 스프링에서 redis를 적용한뒤 테스트 코드를 작성하고 돌렸을시 다음과 같은 오류가 발생한다. 그러나 본 어플리케이션 환경에서는 잘 돌아가기에 원인을 찾는데 시간이 오래 걸렸다. 원인: bean으로 등록된 객체들을 못찾아와 생기는 문제 해결: @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class RedisTest { .... } @SpringBootTest 어노테이션을 추가해 본래 어플리케이션에 추가된 설정을 테스트 환경에서도 똑같이 재현한다. 즉, redisTemplet 을 빈으로 등록한다. 다만 이를 사용하면 단위 테스트 속도가 느려질수 있다는 단점이 존재한다. 2024. 2. 4.
java.lang.IllegalArgumentException: Name for argument of type [java.lang.Integer] not specified, and parameter name information not available via reflection - 스프링. 파라미터 어노테이션에 자동 이름 부여가 안되는 오류 오류 상황 @GetMapping("/test") public String test(@RequestParam Integer data){ return "ok"; } 이 컨트롤러에 http://localhost:8080/test?data=10 요청시 java.lang.IllegalArgumentException: Name for argument of type [java.lang.Integer] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag. 오류가 터지며 응답이 안된다. 원인 원래는 자동으로 변수 이름이 @RequestParam.. 2024. 1. 31.
Parameter 0 of constructor in 컨트롤러 클래스 required a bean of type '클래스 이름' that could not be found. 스프링 에러 빈이 정상적으로 등록되지 않았을때 발생하는 문제다. 문제 원인은 대부분 다음과 같다. 1. @Service, @Repository 같은 어노테이션을 안붙임. 2. @Component 을 붙여주거나 직접 @Configruation 클래스에서 @Bean 어노테이션을 이용해 빈으로 등록 3. Application 실행 클래스 하위 패키지에 빈 클래스를 생성 -> 내 케이스 나는 3번의 케이스, 즉, @ComponentScan 대상이 아닌 패키지에 클래스를 생성한 것이 문제였다. 2024. 1. 27.