其他分享
首页 > 其他分享> > CommandLineRunner和@PostConstruct区别

CommandLineRunner和@PostConstruct区别

作者:互联网

实现CommandLineRunner接口;容器启动之后,加载实现类的逻辑资源,已达到完成资源初始化的任务;
@PostConstruct;在具体Bean的实例化过程中执行,@PostConstruct注解的方法,会在构造方法之后执行;
@Component
public class TestRun implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.err.println("项目启动成功");
}
}

@PostConstruct
public Object getTest(){
System.out.println(demoConfig.getName());
return demoConfig.getName();
}
 

 

标签:CommandLineRunner,区别,getName,PostConstruct,System,println,demoConfig
来源: https://www.cnblogs.com/huqi96/p/16496474.html