gpt4 book ai didi

java - JavaBean 和 Spring bean 的区别

转载 作者:IT老高 更新时间:2023-10-28 13:46:00 25 4
gpt4 key购买 nike

我是 Spring MVC 的新手,对 Java 中 java bean 的使用有一点了解。
Java bean 和 Spring bean 的基本区别是什么?

最佳答案

JavaBeans:

At a basic level, JavaBeans are simply Java classes which adhere to certain coding conventions. Specifically, classes that

  • have public default (no argument) constructors
  • allow access to their properties using accessor (getter and setter) methods
  • implement java.io.Serializable

Spring Beans:

A Spring bean is basically an object managed by Spring. More specifically, it is an object that is instantiated, configured and otherwise managed by a Spring Framework container. Spring beans are defined in Spring configuration files (or, more recently, with annotations), instantiated by Spring containers, and then injected into applications.

请注意,Spring bean 不必总是 JavaBeans。 Spring bean 可能没有实现 java.io.Serializable 接口(interface),可以在其构造函数中包含参数,等等。

这是 JavaBean 和 Spring bean 之间非常基本的区别。

更多信息请引用以上文字出处,Shaun Abram 的文章JavaBeans vs Spring beans vs POJOs .

关于java - JavaBean 和 Spring bean 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21866571/

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