@Postconstruct
时间: 2023-09-02 16:10:57 浏览: 118
@Construct是一个注解,用于标记一个方法,在Spring容器初始化Bean的时候会自动调用该方法。被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。一般情况下,@PostConstruct注解的方法会在Bean的构造函数执行完毕后被调用,可以用来进行一些初始化操作,比如加载数据字典等。它的执行顺序一般为:构造函数 -> @Autowired注入 -> @PostConstruct方法。在你提供的代码示例中,@PostConstruct注解修饰的init方法会在UserController的构造函数执行完毕后被调用,用于初始化userService实例。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [SpringBoot中@PostConstruct注解作用](https://blog.csdn.net/qq_45335399/article/details/126885872)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [@PostConstruct注解详解](https://blog.csdn.net/m0_53288098/article/details/122355201)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [@PostConstruct的作用,以及加载先后顺序](https://blog.csdn.net/libralee233/article/details/122681608)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文