본문 바로가기

전체 글

(291)
[baeldung] Retrieve User Information in Spring Security 더보기 https://www.baeldung.com/get-user-in-spring-security Spring Security를 이용하여 사용자 세부 정보를 검색할 수 있다 Get the User in a Bean The simplest way to retrieve the currently authenticated principal is via a static call to the SecurityContextHolder 현재 인증된 보안 principal 값을 가져오려면 SecurityContextHolder 를 호출한다 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!(authent..
[Spring] Assertions in JUnit 4 and JUnit 5 더보기 https://www.baeldung.com/junit-assertions Assertions Assertions은 테스트에서 해당 Assertion 조건을 지원해주는 메소드이다. (JUnit 4의 Assert 클래스와 JUnit 5의 Assertions 클래스를 통해 액세스) JUnit 5는 JUnit 4의 많은 어설션 메서드를 유지하면서 Java 8 지원을 활용하는 몇 가지 새로운 메서드를 추가했다. JUnit4에도 있는 JUnit 5 어설션 부터 정리한다 assertArrayEquals 예상배열과 실제 배열 동일 여부 확인 @Test public void whenAssertingArraysEquality_thenEqual() { char[] expected = { 'J', 'u', 'p', ..
[Spring] A Spring Custom Annotation for a Better DAO 더보기 https://www.baeldung.com/spring-annotation-bean-pre-processor a custom Spring annotation with a bean post-processor. 예제로 사용할 Generic DAO public class GenericDao { private Class entityClass; public GenericDao(Class entityClass) { this.entityClass = entityClass; } public List findAll() { // ... } public Optional persist(E toPersist) { // ... } } Data Access @Retention(RetentionPolicy.RUNTIME) ..
[Spring] Testing @Cacheable on Spring Data Repositories 더보기 https://www.baeldung.com/spring-data-testing-cacheable Caching in Spring Mechanism Simple Model @Entity public class Book { @Id private UUID id; private String title; } repository interface that has a @Cacheable method public interface BookRepository extends CrudRepository { @Cacheable(value = "books", unless = "#a0=='Foundation'") Optional findFirstByTitle(String title); } unless < 제외 조건 (필..
[Java Stream] skip() vs limit() 더보기 https://www.baeldung.com/java-stream-skip-vs-limit skip() 과 limit() 의 차이 skip() method skip(n) stream 의 n번째 요소를 버리는 중간 작업 n은 음수일 수 없으며, stream 보다 크기가 클 경우 빈 스트림을 리턴시킴 Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .filter(i -> i % 2 == 0) .skip(2) .forEach(i -> System.out.print(i + " ")); 6 8 10 이 나옴 filter 에서 2, 4, 6, 8, 10 이 나옴 여기서 skip 2 i % 2 == 0) .limit(2) .forEach(i -> System.out.print(i + ..
[Java 17] 특징 및 예제 코드 더보기 https://youngwonhan-family.tistory.com/entry/Java-17-%EC%A3%BC%EC%9A%94-%ED%8A%B9%EC%A7%95-with-%EC%98%88%EC%A0%9C-%EC%83%98%ED%94%8C-%EC%BD%94%EB%93%9C 블로그 참조 + 예제코드를 내 것처럼 만들어서 따라해보기 1. record (from java 14) record 는 간결하고 변경 불가한 객체 타입이다 public class Test { private String name; private int numbering; public Test(String name, int numbering){ this.name = name; this.numbering = numbering; } ge..
[Java 17] 알아보기 더보기 https://intrepidgeeks.com/tutorial/differences-and-features-of-different-java-versions#17 Java 8이 대규모 release 였다고 한다 Lambda, stream interface default method Optional new Date and Time API(LocalDateTime, …) 등의 기능이 추가되었다. 특히 요즘 공부하고 있던 stream이랑 default meethod 사용하는 것, repositiory에서 자주 쓰는 Optional 과 new Date and Time API Java11 에서는 Oracle JDK와 OpenJDK 통합 Oracle JDK가 구독형 유료 모델로 전환 서드파티 JDK 로의 이전..
[Spring Test] 더보기 https://youtu.be/rs_ReNmLISw?list=PLwouWTPuIjUj_QqgXlFsqjUwyC0-5dZ_q given when then admin.block()).isInstanceOf(AlreadyBlockedException.class); } @Test void unblock_whenNotBlocked(){ Admin admin = new Admin(); Assertions.assertThatCode(() -> admin.unblock()).isInstanceOf(NonBlockedException.class); } public static class Admin { private boolean blocked = false; public boolean isBlocked() { r..

728x90