반응형

300===Dev Framework/Spring 23

Spring Properties & Profiles 완벽 가이드 🎯

Properties가 뭔가요? 🤔Properties는 애플리케이션의 설정 값들을 외부 파일로 분리하여 관리하는 방식입니다.예를 들어볼까요?개발 환경: db.url=localhost:3306운영 환경: db.url=prod.company.com:3306 이렇게 환경별로 다른 설정값들을 손쉽게 관리할 수 있답니다!Properties 설정 방법 💡1. application.properties 생성# src/main/resources/application.propertiesdb.url=localhost:3306db.username=devdb.password=12342. @PropertySource 설정@Configuration@PropertySource("classpath:/application.proper..

Spring Bean의 생명주기 콜백 메서드 (@PostConstruct & @PreDestroy) 🌱

안녕하세요! 오늘은 Spring Bean의 초기화와 소멸 시점에 실행되는 콜백 메서드에 대해 알아보겠습니다.Bean 생명주기 콜백이 필요한 이유 🤔데이터베이스 연결, 캐시 초기화, 외부 리소스 로딩 등 Bean이 생성된 직후나 소멸되기 직전에 특별한 작업이 필요한 경우가 있습니다.예를 들어볼까요?애플리케이션 시작 시 필요한 설정 파일 로딩데이터베이스 커넥션 풀 초기화임시 파일 정리리소스 해제@PostConstruct 💫Bean이 생성되고 의존성 주입이 완료된 후 실행되는 메서드입니다.@Servicepublic class UserService { private Cache cache; @PostConstruct public void init() { System.out.prin..

Spring 스케줄링 ⏰

안녕하세요! 오늘은 Spring에서 반복 작업을 자동화하는 Spring 스케줄링 대해 알아보겠습니다.Spring Task가 뭔가요? 🤔매일 아침 알람을 맞춰놓는 것처럼:특정 시간에 자동으로 실행되는 작업주기적으로 반복되는 작업비동기로 처리해야 하는 작업Spring Task는 이런 자동화된 작업을 쉽게 구현할 수 있게 해주는 프레임워크입니다!핵심 기능 💫1. @Scheduled 애노테이션@Componentpublic class ScheduledTasks { // 매일 자정에 실행 @Scheduled(cron = "0 0 0 * * ?") public void dailyTask() { System.out.println("매일 자정에 실행되는 작업"); } // 5초..

How do you specify the base packages for component scanning in a Spring configuration class?

To specify the base packages for component scanning in a Spring configuration class, you use the @ComponentScan annotation with the basePackages attribute to indicate which packages should be scanned for components.The Big PictureSpecifying base packages for component scanning in a Spring configuration class is akin to giving precise instructions to a search party on where to look for important ..

728x90
반응형