问题:private ‘xxx’ is never assigned
问题背景:基于前后端分离的springboot项目
问题详述:变量声明后调用相关方法,发现变量为灰色,显示private ‘xxx’ is never assigned
解决措施:添加一个@Resource在灰色变量前
原理分析:按名称注入。
- 将对象注入到 Spring Boot 容器中通常是指将对象交由 Spring 容器管理,以便在需要时能够自动注入到其他对象中。
- 在 Spring Boot 中,可以通过 @Component 及其派生注解(如 @Service、@Repository、@Controller 等)将一个类标记为 Spring 管理的组件,然后在其他组件中使用 @Autowired 或 @Resource 注解将其注入。