一.工程结构
1.1 工程结构
、
1.2 逻辑流程
1.先用注解@component将ApplicationContextUtils放到ioc容器中
2.在使用的类中进行引用。

二 操作案例
2.1 将application实例化放到ioc容器中
package com.ljf.spring.boot.demo.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* @ClassName: ApplicationContextUtils
* @Description: TODO
* @Author: liujianfu
* @Date: 2020/11/03 21:14:43
* @Version: V1.0
**/
@Component //此注解记住一定要加,实例化这个bean放到spring的容器中
public class ApplicationContextUtils implements ApplicationContextAware {
private stat

本文档展示了如何使用Spring的`@Component`注解将`ApplicationContextUtils`类加入到IoC容器中,并在Service和Controller层中引用。通过`ApplicationContextAware`接口获取ApplicationContext实例,实现根据bean名称获取对象。示例包括了从Util类获取bean,创建Service层实例,以及在Controller层调用Service的方法处理请求。
最低0.47元/天 解锁文章
584

被折叠的 条评论
为什么被折叠?



