OAuth 사용자의 정보를 가지고 있는 제3의 서비스로부터 접근 권한을 위임 받아서 웹 사이트의 자원에 접근하는 방식 사용자의 정보를 저장하고 관리해야 하는 부담을 줄일 수 있다. 사용자도 자신의 개인정보를 신뢰할 수 없는 타인에게 제공하는 단점을 해결한다. OAuth 제공자는 네이버, 카카오, 구글 등이 있다. JWT Header, Payload, Signature로 구성된 암호화된 토큰 session 기반 인증 방식과 달리 stateless한 구현이 가능하다. 로그인 흐름 Resource Owner(사용자)가 Client(서버) 자원에 접근하려 하면 Resource Server(OAuth 제공자)의 로그인 창을 호출하여 인증을 요구한다. 로그인을 성공하면 Resource Server에 로그인 API..
i18n internationalization의 축약형 총 20자리 글자 중에 맨 앞 i와 맨 뒤 n을 제외한 나머지가 18글자가 있다고 해서 i18n 이다. MessageSource란? 국제화(i18n)를 지원하는 스프링 인터페이스 하나의 메세지에 대해서 다국어로 표시해주는 기능 제공 Entity 생성 @Entity @Getter @Setter public class Languages { @Id @GeneratedValue private Integer id; private String locale; private String messageKey; private String messageContent; } sample data 생성 쿼리 작성 src/main/resources 경로에 data.sql 파일..
*************************** APPLICATION FAILED TO START *************************** Description: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. 해결 방법 1. cmd(명령프롬프트) 실행 2. netstat -ano 입력 3. PID 확인 4. taskkill /pid PID /f 입력 예) taskkill /pid 1036 /f
증상 서버에서 파일을 읽어오다가 실패하면서 console에 "net::ERR_CONTENT_LENGTH_MISMATCH 200" 출력 원인 서버에서 읽어오는 파일의 크기와 Header에 설정된 파일의 Content-Length의 크기가 달라서 발생 해결 upload 할 때 파일 크기를 추출해서 DB에 저장한다. @PostMapping("/uri") public String upload(@RequestParam("file") MultipartFile file) { Object obj = new Object(); obj.setFileSize((int) file.getSize());//MultipartFile의 getSize() 메소드로 파일 크기를 추출한다. service.insert(obj);//추출한 파..
Controller @PostMapping("/login") public String login( @RequestParam(name="email", required=true) String email, HttpSession session, ModelMap modelMap ){ if("myEmail@seogineer.com".equals(email)) { //로그인 정보를 session.setAttribute(key, value)로 등록시켜준다. session.setAttribute("isLogin", true); session.setAttribute("email", email); } } //session.getAttribute(key)로 session에 저장된 값을 읽을 수 있다. if(session.ge..
트랜잭션(Transaction) 쪼갤 수 없는 하나의 작업 단위 서비스 객체(=비즈니스 로직)는 하나의 트랜잭션으로 동작한다. 트랜잭션의 특징 1. 원자성 : 전체가 성공하거나 전체가 실패하는 것을 의미 2. 일관성 : 트랜잭션이 진행되는 동안 데이터가 변경 되더라도 처음에 트랜잭션을 진행할 때 참조한 데이터로 진행된다. 3. 독립성 : 하나의 특정 트랜잭션이 완료될때까지 다른 트랜잭션이 특정 트랜잭션의 결과를 참조할 수 없다. 4. 지속성 : 트랜잭션이 완료되었을 경우 영구적으로 반영되어야 한다. Spring에서 트랜잭션 사용 1. pom.xml에 라이브러리 추가 org.springframework spring-tx 4.3.5.RELEASE 2. web.xml에 ContextLoaderListener가..
SQL SELECT id, name, content, regdate FROM guestbook ORDER BY id DESC limit :start, :limit; --LIMIT 시작점, 갯수 Controller defaultValue="0"에 의해 처음은 0 번째부터 5개를 출력한다. 그 다음부터 pageCount에 따라 pageStartList에 5, 10, 15 등의 값이 들어갈 수 있다. @Autowired GuestbookService guestbookService; @GetMapping(path="/list") public String list(@RequestParam(name="start", required=false, defaultValue="0") int start, ModelMap mo..
실행 과정 1. 주소창에 http://~/xxxx 입력 2. DispatcherServlet → Controller : Controller에서 path가 /xxxx인 메소드 실행 3. Controller → DispatcherServlet : InternalResourceViewResolver가 가져온 return 값에 "/WEB-INF/views/"와 ".jsp"를 붙임 4. DispatcherServlet → View template : return 받은 "/WEB-INF/views/xxxx.jsp" 경로 파일 실행 (아래 DispatcherServlet 설정 참고) DispatcherServlet(=WebMvcContextConfiguration.java) 설정 @Configuration @Enab..
Maven Project 생성 File - New - Maven Project - Archetype 선택(Group Id : org.apache.maven.archetypes, Artifact Id : maven-archetype-webapp) - Group Id, Artifact Id 입력 - finish 폴더 추가 Maven Project를 최초 생성하면 위와 같은 구조를 가지고 있는데 Maven Project 디렉토리 구조를 만들기 위해서 아래와 같이 main 폴더 하위에 java, resources 폴더를 생성한다. ㄴsrc ㄴmain ㄴjava : 자바 패키지 폴더와 소스 코드가 위치함. ㄴresources : *.properties, *.xml 등 설정파일들이 위치함. ㄴwebapp : WEB..
MVC MVC는 Model-View-Controller의 약자이다. Spring MVC란 스프링 프레임워크 모듈 중에 하나인 Web 모듈이다. Model : Model은 View가 렌더링하는데 필요한 데이터이다. 예) 사용자가 요청한 상품 목록이나 주문 내역 View : 실제로 보이는 부분. Model을 사용해 렌더링한다. Controller : 사용자의 액션에 응답하는 컴포넌트이다. Model을 업데이트하고 다른 액션을 수행한다. Spring MVC 기본 동작 흐름 1. 클라이언트의 모든 요청은 Front Controller(=DispatcherServlet)라는 단 하나만 존재하는 서블릿이 받는다. 2. Front Controller는 요청만 받고 실제 일은 Controller 클래스(Handler ..