분류 전체보기
-
[Java] currentTimeMillis() nanoTime() Instant.now() uuidProgramming/Java 2024. 5. 31. 16:09
Java는 시간 값을 측정하는 두 가지 기본 메소드를 제공한다. System.currentTimeMillis()는 현재 시간을 밀리초 단위로 반환한다.System.nanoTime()은 현재 시간을 나노초 단위로 반환한다. 두 가지 방법은 상당한 차이가 있다. 시간은 계속 흘러가기 때문에 시간을 고유한 값으로 사용하는 경우가 많다. 이런 경우 어떤 메소드로 사용해야 할지 알아보자. System.currentTimeMillis()밀리초 단위 사용(ms)1970년 1월 1일 UTC시작 시점을 기준으로 현재까지 계산시스템 시간을 참조(운영체제의 시간 값을 기준)-> 날짜와 날짜 사이의 갭을 구할 때 사용1초 = 1000밀리초 장점1. thread safe2. 항상 epoch이후 경과된 절대 시간을 반환한다. ..
-
[Spring] Spring에서 JSON 파라미터를 Java객체로 받기Programming/SpringBoot 2024. 5. 27. 15:10
Spring에서 Request,Response로 전달되는 파라미터 정보를 컨트롤러에서 어떻게 Java객체로 받을까?Spring에서 HttpMessageConvert가 그 역할을 담당하고 있다.Request, Response내에는 모두 text형식이라고 할 수 있다. 이를 Java자료형으로 변환해주는 역할을 한다. HttpMessageConvertByteArrayHttpMessageConvertStringHttpMessageConvertFormHttpMessageConvertSourceHttpMessageConvertJax2RootElementHttpMessageConvertMarshallingHttpMessageConvertMappingJackson2HttpMessageConverter....이외에도 S..
-
[Spring] Content-Type 'application/octet-stream' is not supportedProgramming/SpringBoot 2024. 5. 27. 15:01
컨트롤러에서 이미지 파일과 dto를 잘 받아오는지 확인하려는 메소드를 실행했을때 @LoginRequired @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity test(@RequestPart(value = "files") List files, @RequestPart(value = "postDto") PostDto postDto, @LoginMember MemberDto memberDto){ if(files.isEmpty()){ return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } ..
-
[Spring] 로그인 세션 관리Programming/SpringBoot 2024. 5. 21. 17:22
세션Session세션은 서버에 값을 저장한다.서버는 세션을 사용해서 클라이언트의 상태를 유지할 수 있다. 세션 관리는 왜 필요할까?웹은 HTTP 프로토콜을 사용한다.HTTP는 connectionless, stateless 특징을 가지고 있다.비연결성, 서버가 클라이언트의 상태를 저장하지 않는다는 것이다.어떤 사용자가 어떤 세션을 사용하고 있는지 알 수 없기 때문에 세션 관리가 필요하다.즉, 로그인한 사용자 정보를 유지하기 위한 목적으로 세션을 사용한다. session의 동작 과정Spring Boot는 기본 서블릿 컨테이너로 Tomcat을 사용한다.Tomcat의 경우 세션 id로 JSESSIONID를 사용한다. 서버에서 세션을 만드는 시점은?클라이언트가 요청하면 서버에서 세션 아이디가 없을 때 세션을 만들..
-
[Project] day 11 : Spring sessionProject 2024. 5. 17. 16:31
즉 우리가 웹어플리케이션을 개발할 때 사용하는 HttpSession도 Servlet Container가 생성한 인스턴스이다.Spring은 Servlet Container가 만든 HttpSession을 주입할 뿐, HttpSession을 생성하는 주체는 Servlet Container이다.(참고로 SpringSession을 이용한다면 Servlet Container가 생성한 구현체가 아니라 SpringSession이 생성한 구현체가 될 것. 참고 https://velog.io/@dmchoi224/Session-HttpSession-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4.-%EC%BF%A0%ED%82%A4 https://medium.com/sjk5766/be..
-
[Spring] 테스트 코드Programming/SpringBoot 2024. 5. 14. 13:51
단위 테스트, 통합 테스트단위 테스트 Unit Test작은 단위의 코드에 대해 테스트를 수행하는 것개발자가 설계하고 만든 코드가 원래 의도대로 동작하는지를 개발자가 스스로 빠리 확인 받기 위해서 한다. 스프링부트에서의 단위 테스트와 통합 테스트를 구분하는 것으로 "@SpringBootTest 어노테이션 사용 유무"를 들 수 있다.@SpringBootTest 어노테이션을 사용하지 않는 것을 단위 테스트라고 하자.이는 스프링을 전혀 실행하지 않는다는 것이다. 디팬던시가 전혀 없는 상황에서 실행할 수 있는 테스트이다. 통합 테스트 Integration Test @SpringBootTest 어노테이션을 사용한다면 통합 테스트라고 하자.@SpringBootTest는 스프링을 실행시켜야 한다. 따라서 Spring..
-
[Project] Day10Project 2024. 5. 11. 14:28
CREATE TABLE members(member_id BIGINT AUTO_INCREMENT Primary Key, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, created_time TIMESTAMP, modified_time TIMESTAMP); BCryptPasswordEncoder 이외에도 LdapShaPasswordEncoder : `Deprecated` 다이제스트 기반 비밀번호 인코딩은 안전하지 않은 것으로 간주되어 더 이상 사용되지 않습니다. base64 인코딩 NoOpPasswordEncoder : `Deprecated` 레거시 구현으로 안전하지 않아 더 이상 사용되지 않습니다. 인코딩과정이 없고 평문으..
-
[Spring] dataSource or dataSourceClassName or jdbcUrl is required.Programming/SpringBoot 2024. 5. 11. 13:56
java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required. DB연결을 하기 위해 DatabaseConfig파일을 만들고 Bean으로 만들려고 하는데 발생한 에러! 찾아본 결과 스프링 커넥션 풀의 차이에서 나타났는데SrpingBoot 2.0이전에는 tomcat-jdbc 를 사용하다, 2.0이후에는 HikariCP를 기본옵션으로 채택하고 있다. 그렇기 때문에 설정 방식에 조금 차이가 있다. 1. application.properties 파일url을 jdbc-url로 수정spring.datasource.url -> spring.datasource.jdbc-urlHikariCP의 Database URL설..