본문 바로가기

▶ Back-End/Java47

SpringBoot Security Login 기능 추가 아주 간단한 Spring Security Login 기능 추가 방법 *Maven 사용 *Spring Boot Project 생성 과정 생략 *자세한 설명 생략 ▷ pom.xml *의존성 추가 org.springframework.boot spring-boot-starter-security ▷ application.properties *사용자 지정 ID/PWD 설정 * Default user ID : user * Default user Pwd : 서버 실행 시 제공( Using generated security password: fd67f8d9-652b-46cd-a147-4b6681292d50 ) spring.security.user.name = test spring.security.user.password.. 2023. 9. 26.
Objcet to String Object를 String으로 변환하는 간단한 방법 /** * * Object to String * * @param Object * @return String */ public static String getObjStr(Object obj) { String str = ""; try { str = new ObjectMapper().writeValueAsString(obj); } catch (Exception e) { log.error("getObjStr Err : {}", e); } return str; } 2023. 9. 21.
@Value 사용법 application.properties에 설정한 값을 가져와 사용하는 @Value *자세한 설명 생략 ▷ application.properties *Test를 위한 값 설정 # value test.val = HELLO # map test.mapInt = {W:0, O:1, R:2, L:3, D:4} test.mapStr = {W:'w', O:'o', R:'r', L:'l', D:'d'} # list test.listInt = 0, 1, 2, 3, 4 test.listStr = H, E, L, L, O ▷ Application.java *간단한 Test를 위해 Application.java에서 진행 *Bean이 생성된 후 사용해야 하기 때문에 CommandLineRunner 사용 *CommandLineR.. 2023. 9. 21.
LocalTime AVG LocalTime 평균 구하기 *parameter는 상황에 따라 변경해서 사용(LocalTime t1, LocalTime...ts) /** * LocalTime AVG * * @param List * @return AVG LocalTime */ public static LocalTime getLocalTimeAVG(List list) { LocalTime result = LocalTime.of(0, 0, 0); if (!list.isEmpty()) { long nanoSum = 0L; for (LocalTime time : list) { nanoSum += time.toNanoOfDay(); } result = LocalTime.ofNanoOfDay(nanoSum / (list.size())); } re.. 2023. 9. 21.
String to LocalTime String time format은 상황에 따라 변경해서 사용 /** * String(HHmmss) to LocalTime * * @param String(HHmmss) * @return LocalTime(HH:mm:ss) */ public static LocalTime getStrLocalTime(String str) { return LocalTime.parse(str, DateTimeFormatter.ofPattern("HHmmss")); } 2023. 9. 21.
String to LocalDate String date format은 상황에 따라 변경해서 사용 /** * String(yyyyMMdd) to LocalDate * * @param String(yyyyMMdd) * @return LocalDate(pattern) */ public static LocalDate getStrLocalDate(String str) { return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyyMMdd")); } *개선한 버전 /** * String(yyyyMMdd) to LocalDate * * @param String(yyyyMMdd) * @return LocalDate(pattern) */ public static LocalDate getStrLocalDa.. 2023. 9. 21.
Ramdom LocalTime 생성 원하는 시간의 Random LocalTime 생성 /** * getRandomTime * * @param LocalTime (LocalTime.of(0, 0, 0)) * @param LocalTime (LocalTime.of(0, 0, 0)) * @return LocalTime(HH:mm:ss) */ public LocalTime getRandomTime(LocalTime startTime, LocalTime endTime) { return LocalTime.ofSecondOfDay(ThreadLocalRandom.current().nextInt(startTime.toSecondOfDay(), endTime.toSecondOfDay())); } 2023. 9. 21.
Random LocalDate 생성 원하는 기간의 Random LocalDate 생성 /** * getRandomDate * * @param String(yyyyMMdd) * @param String(yyyyMMdd) * @return LocalDate(yyyy-MM-dd) */ public LocalDate getRandomDate(String startDate, String endDate) { LocalDate fromDate = LocalDate.of( Integer.parseInt(startDate.substring(0, 4)), Integer.parseInt(startDate.substring(4, 6)), Integer.parseInt(startDate.substring(6, 8))); LocalDate toDate = Loca.. 2023. 9. 21.
SpringBoot + Cassandra 연동(Multi Node) Docker에 설치한 Cassandra(Multi Node)와 SpringBoot 연동 *spring-boot-starter-parent 2.3.10.RELEASE 기준 *Docker에 Application을 올리는 과정 *자세한 설명 생략 ▷ 이슈 사항 확인 !! 이슈 → Local Host에서 Multi Node를 연동할 때 Docker Network 문제 발생 *SpringBoot는 Docker Containerr IP로 노드에 연결 시도 *Single Host Multi Node(Docker Container) 환경에서 발생 *Error log [WARN ] : [s0|/172.19.0.3:9042] Error while opening new channel (ConnectionInitExcepti.. 2023. 8. 18.
728x90
728x90