gpt4 book ai didi

spring - Spring容器就像jvm一样吗?

转载 作者:行者123 更新时间:2023-12-02 20:12:07 25 4
gpt4 key购买 nike

Spring Container 就跟 jvm 一样吗?或者它是不同的?为什么主要使用Spring IOC?如果是为了不使用new运算符来创建对象?使用 new 运算符有什么问题?

如果我们创建单例对象并在应用程序需要时返回相同的对象,那么我们会在服务器启动时加载所有对象吗?这不会使应用程序变得很重吗?

如果是这样,那为什么我们需要 Spring 芯呢?filter、bean后处理器、aop有何不同?如果使用aop来实现横切关注点,为什么还需要beanProcessor接口(interface)?

最佳答案

Is Spring Container is just like a jvm?

不,Spring 是一个 Java 框架。它提供了可用于在 JVM 上运行 Java 应用程序的类。

Why is Spring IOC mainly used?

Learn what Inversion of Control is and you will understand why it is used so heavily.

If it is for creating the objects without using new operator? what is wrong in using new operator?

new 关键字强制编译时依赖性。控制反转和依赖注入(inject)主要通过反射来消除这些依赖关系。

If we are creating singleton objects and return the same object whenever application wants, we are loading all the objects on server start up? will that not make the application heavy?

您通常会在启动时需要所有这些对象,因此这不是问题。您可以通过延迟加载来延迟这些对象(bean)的初始化。

If it is so, then why we need spring core?

如果是什么是这样?

How is filter,bean post processor, aop is different?

BeanFactory 创建并初始化 bean。 BeanPostProcessor 旨在将 bean 包装在代理中或修改该 bean 的属性。 javadoc有更多详细信息。

面向方面的编程是一种编程风格。为了使用普通的旧式 Java 来实现它,您需要使用 JDK 或 CGLIB 代理。这些是通过包装处理后的 bean 使用 BeanPostProcessor 实例来应用的。对目标 bean 的调用将被代理拦截,代理将(可能)在委托(delegate)给目标 bean 之前执行逻辑。 Java 的 AOP 功能几乎完全局限于方法调用。

关于spring - Spring容器就像jvm一样吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20228389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com