JavaBean和Spring bean之间的区别 [英] Difference between JavaBean and Spring bean
问题描述
我是Spring MVC的新手,并且对Java中Java Bean的使用有所了解.
Java bean和Spring bean之间的基本区别是什么?
I am new to Spring MVC and have a little idea of the usage of java beans in Java.
What is the basic difference between a Java bean and Spring bean?
推荐答案
JavaBeans:
从根本上讲,JavaBeans只是遵守某些编码约定的Java类.具体来说,
JavaBeans:
At a basic level, JavaBeans are simply Java classes which adhere to certain coding conventions. Specifically, classes that
- 具有
public
默认(无参数)构造函数 - 允许使用访问器(getter和setter)方法访问其属性
- 实现
java.io.Serializable
- have
public
default (no argument) constructors - allow access to their properties using accessor (getter and setter) methods
- implement
java.io.Serializable
春豆:
Spring bean本质上是由Spring管理的对象.更具体地说,它是一个由 Spring框架容器实例化,配置和管理的对象. Spring Bean是在Spring配置文件中定义的(或者,最近带有注释),由Spring容器实例化,然后注入到应用程序中.
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
接口,可以在其构造函数中包含参数,等等.
Note that Spring beans need not always be JavaBeans. Spring beans might not implement the java.io.Serializable
interface, can have arguments in their constructors, etc.
这是JavaBean和Spring Bean之间最基本的区别.
This is the very basic difference between JavaBeans and Spring beans.
有关更多信息,请参考上述文本的来源,Shaun Abram的文章 JavaBeans,Spring bean和POJOs .
For more information, refer to the source of the above text, Shaun Abram's article JavaBeans vs Spring beans vs POJOs.
这篇关于JavaBean和Spring bean之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!