SSM:
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
@Component
public class Init implements InitializingBean{
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("初始化了");
}
}
Springboot:
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class InitRedisData implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
initKeyword();
}
public void initKeyword(){
System.out.println("我执行了");
}
}
可以定义多个初始化类,使用@Order决定执行先后顺序。