Framework/Spring
-
[Springboot/BeanUtils] @Autowired null 문제 해결 (ApplicationContext로 Bean 주입)Framework/Spring 2019. 5. 24. 10:22
새로 생성한 Thread 내에서 DB Mapper의 Service를 호출하여 DB 처리를 하려고 했다. 하지만 @Autowired로 불러온 Service는 null만 띄울 뿐 동작하지 않았다. (Bean으로 등록되는 클래스 내에서만 @Autowired 가 동작) Spring에서 Bean은 IOC Container가 자동으로 주입해주는데 ApplicationContextProvider를 이용하여 Bean을 수동으로 주입 가능하다. @Component public class ApplicationContextProvider implements ApplicationContextAware{ private static ApplicationContext applicationContext; @Override publi..
-
[Quartz] SpringBoot 에서 동적으로 properties 파일 읽어 Cron 설정 변경Framework/Spring 2019. 5. 21. 16:40
SpringBoot 환경에서 스케쥴링을 설정하는 방법은 쉽다. 메인 함수 위에 @EnableScheduling 어노테이션을 달고 스케쥴링을 설정할 함수 위에 @Scheduled(fixedDelayString ="600000") //600000은 ms 단위로 = 10분 혹은 @Scheduled(cron = "*/10 * * * * *") // Cron 표현식, 10초에 1번 실행 어노테이션을 달아주기만 하면 된다. 하지만 나는 Cron 표현식을 변경하여 설정해놓은 properties 파일을 변경하면 프로그램을 재시작하지 않아도 자동으로 적용되는 프로그램을 만들고 싶었다. 여기서 사용하게 된 것이 commons-configuration2 와 spring-boot-starter-quartz 이다. common..
-
[MVC] Controller - View : Cookie로 작업 종료 알림Framework/Spring 2019. 3. 29. 11:51
View 에서 작업을 실행시키고 종료에 따른 이벤트를 구현할 때는 보통 ajax를 이용했다. 하지만 Controller로 background 작업을 할 때 작업 종료 알림을 받아야 하는 경우가 있다. (Excel 파일 생성 완료 후 알림) View에서는 Cookie를 생성하고 주기적으로 Cookie를 검사하여 값이 바뀌면 작업을 종료한다. Controller에서 작업이 끝나면 Cookie의 값을 바꿔 return 해준다. - 이를 이용해 File Download 중 loading bar나 progress bar 구현이 가능하다. //view.jsp /** javascript 함수 호출 부분**/ setCookie("fileDownloadToken","false"); //Cookie 생성 checkDown..