Spring Boot PostConsruct

匿名 (未验证) 提交于 2019-12-02 23:26:52

先 autowired
autowired 之后再执行

package com.example.demo;  import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Component;  import javax.annotation.PostConstruct;  @Component class A { 	void print() { 		System.out.println("A"); 	} }  @Component class B { 	@Autowired 	A a;  	@PostConstruct 	void init() { 		a.print(); 	} }  @SpringBootApplication public class DemoApplication {  	@Autowired 	B b;  	public static void main(String[] args) { 		SpringApplication.run(DemoApplication.class, args); 	} } 
文章来源: https://blog.csdn.net/YYecust/article/details/88846203
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!