static|static 和 @postconstruct区别
static 和 @postconstruct区别:
static blocks are invoked when the class is being initialized, after it is loaded. The dependencies of your component haven't been initialized yet. That is why you get a NullPointerException (Your dependencies are null) .
Move your code to a method annotated with @PostConstruct. This will ensure that your code will run when all the dependencies of your component are initialized
翻译:static模块会被引入,当class加载后。你的component组件的依赖还没有初始化。这就是为什么你的代码块会报空指针异常。(你的依赖都是null)
【static|static 和 @postconstruct区别】把你的代码移到一个@PostConstruct声明的方法块中,这样可以确保你的代码执行在所有组件都加载以后。
推荐阅读
- 急于表达——往往欲速则不达
- 第三节|第三节 快乐和幸福(12)
- 20170612时间和注意力开销记录
- 2.6|2.6 Photoshop操作步骤的撤消和重做 [Ps教程]
- 对称加密和非对称加密的区别
- 眼光要放高远
- 樱花雨
- 前任
- 2020-04-07vue中Axios的封装和API接口的管理
- 烦恼和幸福