Framework & Library/Spring & String boot

[Spring] Running code after Spring Boot Run

yjkim_97 2021. 6. 21. 11:31

spring boot run 이후 초기에 한번 실행되는 코드

package com.innerwave.surfinn;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;

import com.innerwave.surfinn.business.common.AuthCacheManager;

@SpringBootApplication
@EnableCaching
public class SpringSecurityApplication {
	private static final String PROPERTIES = "spring.config.location="
	        +"classpath:/config/application.yml"
	        +",classpath:/authentication-config.yml"
	        ;
	
	public static void main(String[] args) {
    
		ConfigurableApplicationContext context = new SpringApplicationBuilder(SpringSecurityApplication.class)
        	.properties(PROPERTIES)
        	.run(args);
		
		context.getBean(AuthCacheManager.class).setCacheInitial();
	}

}

ConfigurableApplicationContext context = SpringApplicationBuilder..run();

context.getBean( 클래스 ).메소드()