반응형

Framework/Spring Boot 69

[Error] Error creating bean with name 'emailConfig': Injection of autowired dependencies failed;

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emailConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.mail.username' in value "${spring.mail.username}" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(A..

redirect

클라이언트가 서버로 요청함 서버가 다른 URL로 리다이렉트함 클라이언트가 바뀐 URL로 다시 서버에 요청 👇 참고 https://webstone.tistory.com/65 리다이렉트란(Redirect) HTTP 리다이렉트(Redirect)란? 리다이렉트란 말 그대로 re(다시) + 지시하다(direct) 다시 지시하는 것을 말한다. 예를 들어 브라우저가 www.webstone.com/blogA URL을 웹 서버에 요청했다고 하.. webstone.tistory.com

@RequestParam | @PathVariable | @RequestBody | @ModelAttribute

@RequestParam 사용 예시 @PostMapping("/user/phoneCheck") // 전화번호 중복 검사 @ResponseBody public boolean phoneCheck(@RequestParam("phone") String phone){ LOG.info("userPhoneCheck 진입"); LOG.info("전달받은 번호:"+phone); boolean flag=userService.userPhoneCheck(phone); LOG.info("확인 결과:"+flag); return flag; } /user/phoneCheck?phone=01012345678 프런트엔드에서 name과 RequestParam 변수명이 같아야 함 @RequestParam Map params Map 타입으로..

개인정보 수정

@GetMapping("/user/form") // 개인정보 수정 public String updateForm(Model model){ Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String id=authentication.getName(); // 로그인한 유저 id model.addAttribute("user", userService.findByUsername(id).get()); return "/user/updateForm"; } 유저 아이디를 이용해서 객체를 찾아 model에 담았다. 개인정보수정 개인정보수정 버튼은 사용자가 로그인했을 때 보인다. 참고 👇 https://flyburi...

@DataJpaTest와 @SpringBootTest

@DataJpaTest @SpringBootTest JPA 테스트와 연관된 config만 적용 full application config를 로드 자동으로 롤백 수동 롤백 in-memory DB를 이용해 테스트 @Component 빈은 @SpringBootTest를 쓰자. 참고 👇 https://krksap.tistory.com/1013 @SpringBootTest와 @DataJpaTest 차이점 @SpringBootTest와 @DataJpaTest 차이점 Spring Application(스프링 어플리케이션)은 ApplicationContext이다. 스프링의 기본 컨셉이 ApplicationContext에 Bean(Object)들을 미리 로드 해놓고 사용하는 컨셉이기.. krksap.tistory.com..

[Error] The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!

@Test public void joinUser(){ //given User user1=new User(); user1.setUsername("spring00"); user1.setEmail("abc@naver.com"); user1.setEnabled(true); user1.setName("스프링"); user1.setPassword("lovespring00!"); user1.setPhone("01012345678"); user1.setRoles(new ArrayList()); // when userService.joinUser(user1); // then User findUser=userRepository.findById(user1.getId()).get();// 에러가 발생한 부분 assertTha..

[Error] 아이디 중복 체크

ajax로 아이디 값을 입력받을 때마다 서버에 전송해서 boolean 값을 받는다. boolean existsByUsername(String id); 를 이용해서 데이터베이스에서 아이디 중복 체크를 했다. 문제점 서버에서 넘긴 flag는 boolean이다. 프런트단에서 출력하니까 엉뚱하게 회원가입 html 소스 코드가 나타난다. '/user/idCheck'으로 가야하는데 안 가는 것 같다. 로그가 안 찍힌다. ✨ 해결 원인은 스프링시큐리티였다. 홈과 회원가입 페이지만 접근을 허용해서 '/user/idCheck'가 차단된 것이다. post 방식으로 요청한 '/user/idCheck'에 가지 않고, '/user/joinForm'에 가서 return 값이 회원가입 html 소스 코드다. 로그인 안 해도 접근할..

Spring Security 사용자 id 가져오기

Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String username = ((UserDetails)principal).getUsername(); 작성한 글을 저장할 때 작성자를 로그인 한 id로 해주었다. 위의 코드를 추가하면 로그인 한 유저의 id를 가져올 수 있다. 참고 👉 https://dzone.com/articles/how-to-get-current-logged-in-username-in-spring-se Spring Security: Access Current Logged-In Username - DZone Security This tutorial demonstrates ho..

[ERROR] EL1004E: Method call: Method hasError(java.lang.String) cannot be found on type org.thymeleaf.spring5.expression.Fields

🦔 에러 로그 Exception evaluating SpringEL expression: "#fields.hasError('content')" (template: "post/detail" - line 49, col 27) EL1004E: Method call: Method hasError(java.lang.String) cannot be found on type org.thymeleaf.spring5.expression.Fields s를 빼먹어서 생긴 에러였다 ㅠㅠ "#fields.hasErrors('content')"가 맞다.

반응형