반응형
date format 하는과정에서 오류가 났다.
현재 날짜를 가져와서 그 날짜를 format 하는과정에서 오류가 난것같다.
- 에러 로그
2023-01-26 17:55:30 ERROR [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler:95] - Unexpected error occurred in scheduled task.
java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:342) ~[?:?]
at java.text.Format.format(Format.java:159) ~[?:?]
at com.pangpany.dcaf.schedule.ScheduleUtil.kopisSendCron(ScheduleUtil.java:157) ~[Dcaf-Common-1.0.0.jar:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
at java.lang.Thread.run(Thread.java:833) [?:?]
2023-01-26 17:56:00 INFO [com.pangpany.dcaf.schedule.ScheduleUtil:147] - #############kopis전송test#############
2023-01-26 17:56:00 ERROR [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler:95] - Unexpected error occurred in scheduled task.
java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:342) ~[?:?]
at java.text.Format.format(Format.java:159) ~[?:?]
at com.pangpany.dcaf.schedule.ScheduleUtil.kopisSendCron(ScheduleUtil.java:157) ~[Dcaf-Common-1.0.0.jar:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
at java.lang.Thread.run(Thread.java:833) [?:?]
- 문제가 된 부분
LocalDate now = LocalDate.now();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String formatedNow = formatter.format(now);
해결!
LocalDate 객체를 Date 객체로 바꿔줬다.
simpleDateFormat 은 정해진 형식만 format을 해줄수 있는데
LocalDate로 현재날짜를 추출하면 아래와같이 값이 나온다.
이 형태의 값으로는 simpleDateFormat가 format을 해주지 못한다
따라서 아래처럼 Date객체로 추출한 현재날짜로 format을 해주어야 정상적으로 작동한다.
최종적으로,
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String formatedNow = formatter.format(now);
요렇게 바꿔줬더니
오류가 발생하지 않고 정상적으로 작동했다!
반응형
'나의 개발 기록 > ERROR !!' 카테고리의 다른 글
[error] 이클립스 SVN Connector 설치 오류 connector discovery completed without finding any connectors. (2) | 2023.12.20 |
---|---|
org.json.simple.JSONObject and org.json.JSONObject are in unnamed (0) | 2023.02.17 |
[error/전자정부프레임워크] /j_spring_security_check 404오류 (1) | 2022.10.13 |
java.lang.StringIndexOutOfBoundsException: begin -1, end 0, length 0 (0) | 2022.09.27 |
[Oracle] ORA-00984: 열을 사용할 수 없습니다 (0) | 2022.09.01 |
댓글