我使用的是springboot+mybatisplus +mysql1.创建一个SpringUtil工具类 import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public final class SpringUtil im
spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). 解决方法:将要注入的 service 改成 static,就不会为null了.参考代码: @Controller @ServerEndpoint(value="/chatSocket") public class ChatSocket { // 这里使用静态,让 service 属于类
1. 简介 为了写 Spring IOC 容器源码分析系列的文章,我特地写了一篇 Spring IOC 容器的导读文章.在导读一文中,我介绍了 Spring 的一些特性以及阅读 Spring 源码的一些建议.在做完必要的准备工作后,从本文开始,正式开始进入源码分析的阶段. 在本篇文章中,我将会详细分析BeanFactory的getBean(String)方法实现细节,getBean(String) 及所调用的方法总体来说实现上较为复杂,代码长度比较长.作为源码分析文章,本文的文章长度也会比较长,