Web
배포 환경 AWS EC2 Ubuntu 16.04.6 1. git 설치 여부 확인 $ git --version => git version정보가 잘 출력된다면 설치되어있는 것. git이 설치되어 있지 않다면 아래 명령어를 통해 git 설치 $ sudo apt-get install git 2. nvm 설치하기 $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash 3. nvm 활성화하기 $ . ~/.nvm/nvm.sh 4. nvm에 node 설치하기 $ nvm install node 5. node 설치 확인 $ node -v => 설치된 node의 version정보가 잘 뜨면 설치 완료 [참고] nvm에서 node 버전..
이 글은 nginx, python이 모두 설치되어 있고 도메인을 가지고 있는 상태에서 따라하시면 됩니다. 테스트 환경 AWS EC2 (Ubuntu 16.04.6 LTS) nginx/1.10.3 Python 2.7.12 1. Certbot 설치하기 apt에 repository를 추가해줍니다. $ sudo add-apt-repository ppa:certbot/certbot apt를 업데이트 해줍니다. $ sudo apt-get update python-certbot-nginx 를 설치해줍니다. $ sudo apt-get install python-certbot-nginx 2. nginx 설정에 도메인을 설정하기 $ sudo vi etc/nginx/sites-available/default 설정파일을 에디터..
입력된 아이디가 없다거나 비밀번호가 틀리다면 로그인을 실패를 할 것이다. 이번 글에서는 로그인이 실패를 했을 경우 어떠한 핸들러를 가지고 처리를 해줄 수 있는지에 대하여 간단한 예제로 살펴보겠습니다. AuthenticationFailureHandler Spring Security에 정의되어 있는 Interface로 이 핸들러를 구현해주고 SecurityConfig에서 설정을 해주면 자동으로 핸들러로 등록이 된다. onAuthenticationFailure(...) 위의 AuthenticationFailureHandler에 정의되어 있는 메서드이다. 매개변수로는 HttpServletRequest(request의 정보를 가지고 있다.), HttpServletResponse(response에 대한 설정을 할 ..
[Spring Boot] Thymeleaf를 사용해 PathVariable 넘기는 방법 CRUD에서 Create를 제외하고는 URL에 해당 객체의 id값을 넘겨주어서 구현을 해줄 수 있다. Spring Boot에서는 Controller에서 @PathVariable 어노테이션을 사용하여 URL의 인자값을 전달받을 수 있는데 그렇다면 Thymeleaf에서는 어떠한 방법으로 id값을 넘겨주어야 되는지에 대하여 알아보겠다. Controller에서 delete를 처리하는 메서드 @GetMapping("todoDelete/{id}") public String delete(@PathVariable Long id) { todoService.delTodo(id); return "redirect:/"; } URL에서 id..
Spring Security를 사용하여 간단하게 회원가입과 로그인 및 로그아웃 기능을 구현해보겠습니다. Django에서 auth와 같은 기능과 유사하다고 생각이 들었습니다. 그럼 이제 간단한 설명과 함께 코드를 살펴보겠습니다. 프로젝트 환경 Spring Boot 2.2.6 Java 11 Gradle Dependencies Spring-boot-starter-Web Spring-boot-starter-Data-JPA Spring-boot-starter-Sequrity Spring-boot-starter-thymeleaf Lombok implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' Thymeleaf에서 Spring ..
@ControllerAdvice 모든 또는 여러개의 컨트롤러에 같은 @ExceptionHandler, @InitBinder, @ModelAttributes를 적용하고 싶은 경우 사용할 수 있다. BaseController를 생성 @ControllerAdvice(assignableTypes = {EventController.class, EventApi.class}) public class BaseController { @ExceptionHandler public String eventErrorHandler(EventException exception, Model model) { model.addAttribute("message","event error"); return "error"; } @InitBind..
@ExceptionHandler 특정 예외가 발생할 경우 발생한 요청을 처리해주는 핸들러 EventException이라는 클래스를 만든다. (RuntimeException 상속) public class EventException extends RuntimeException { } @ExceptionHandler 정의 @ExceptionHandler public String eventErrorHandler(EventException exception, Model model) { model.addAttribute("message","event error"); return "error"; } @ExceptionHandler public String runtimeErrorHandler(RuntimeExcepti..
@InitBinder 특정 컨트롤러에서 바인딩 또는 검증 설정을 변경하고 싶을 때 @InitBinder를 이용해 설정값을 지정할 수 있다. 사용법 @InitBinder public void initEventBinder(WebDataBinder webDataBinder) { ... (설정) } // 특정 모델 객체에만 적용을 하고 싶을 경우 아래와 같이 이름을 지정. @InitBinder("event") public void initEventBinder(WebDataBinder webDataBinder) { ... (설정) } 바인딩 설정 @InitBinder public void initEventBinder(WebDataBinder webDataBinder) { webDataBinder.setDisall..
@ModelAttribute의 또 다른 사용법 @ModelAttribute의 사용법에서 살펴본 것과 별개로 또 다르게 사용하는 @ModelAttribute에 대해 알아보겠다. @ModelAttribute public void categories(Model model) { model.addAttribute("categories",List.of("study", "seminar", "hobby", "social")); } // 또는 @ModelAttribute("categories") public List categories(Model model) { return List.of("study", "seminar", "hobby", "social"); } 위와 같이 @ModelAttribute를 사용하게되면 이 ..