spring

使用工厂模式去进行ioc解耦

使用v1

就是使用工厂去创建对象

csharp 复制代码
package com.healer.beanFactory_v1;

import com.healer.mapper.UserMapper;
import com.healer.mapper.impl.UserMapperImpl;
import com.healer.service.UserService;
import com.healer.service.impl.UserviceImpl;

/**
 * @author healer
 * @Description BeanFactory_v1
 * @data 2024-06-13 17:14
 */
public class BeanFactory_v1 {

    public static UserService getUserService() {
        return new UserviceImpl();

    }


    public static UserMapper getUserMapper() {
        return new UserMapperImpl();

    }

}

使用 v2版本

加载properties进行创建对象

需要使用 user.properties

首先创建这个的作用是

需要使用工厂去创建对象

那么就需要配置对象的属性

csharp 复制代码
userMapper=com.healer.mapper.impl.UserMapperImpl
userService=com.healer.service.impl.UserviceImpl

然后再 beanfactory中去创建对象

通过name去获取

这个版本获取的bean对象也不是单例的

所以引入v3版本

使用的是ioc思想

当类加载的时候 对象就以及实例化完成并加载到ioc容器中

这个容器是,map集合

然后再静态代码块中将对象加入到map容器中

此后就可以直接拿对象

相关推荐
葫芦和十三34 分钟前
图解 MongoDB 08|ESR 原则:复合索引的字段顺序怎么定
后端·mongodb·agent
葫芦和十三8 小时前
图解 MongoDB 07|索引类型:七种索引,七种访问形状
后端·mongodb·agent
朦胧之10 小时前
AI 编程-老项目改造篇
java·前端·后端
爱勇宝12 小时前
我做了一个只用来搜歌词的小 App
android·前端·后端
IT_陈寒13 小时前
SpringBoot自动配置坑了我一晚上,原来问题出在这
前端·人工智能·后端
SelectDB14 小时前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
SelectDB14 小时前
秒级弹性、最高降本 70%:SelectDB Serverless 如何重塑云数仓资源效率
大数据·后端·云原生
程序猿大帅14 小时前
别再只当调包侠了:用 Spring AI 落地 Function Calling,我被大模型硬生生砸出了三个大坑
java
PinkSun14 小时前
Spring AI ChatMemory踩坑实录:重启丢数据、Agent丢记忆、对话溢出
后端·ai编程
壹方秘境14 小时前
我用Go语言开发了一个跨平台的HTTPS抓包和调试工具
前端·后端·ios