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?

- 10,785
- 7
- 42
- 56

- 2,159
- 2
- 14
- 9
-
http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/htmlsingle/#beans-definition – JB Nizet Feb 18 '14 at 22:12
-
They're completely different patterns. JavaBean: http://stackoverflow.com/q/3295496/139010 – Matt Ball Feb 18 '14 at 22:12
-
They are plain POJOs whose lyfecycle is maintained by a container. JavaBeans are managed by a Java *standard*(?) container e.g. JSF Managed Beans, EJBs, CDI beans... while Spring beans are managed by the Spring container. – Luiggi Mendoza Feb 18 '14 at 22:16
4 Answers
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.
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.
This is the very basic difference between JavaBeans and Spring beans.
For more information, refer to the source of the above text, Shaun Abram's article JavaBeans vs Spring beans vs POJOs.
Java bean is a class that should follow following conventions:
1.Must implement Serializable. 2.It should have a public no-arg constructor. 3.All properties in java bean must be private with public getters and setter methods.
Spring beans are the objects that form the backbone of your application and are managed by the Spring IoC container .

- 71
- 1
- 2
Spring Bean:
A class which is developed as part of a spring application. Its life cycle which is managed by Spring Container is called as Spring Bean.
-
1
-
5Welcome to SO, kindly make sure before you post an answer at least look that thread for other positive score answers or accepted ones then decide if your amswer is adding something useful then its okay else refrain from posting it – mfaisalhyder Oct 20 '17 at 05:24
Java beans and Spring beans are more related than different.
For a Java class to be usable as a Java bean, its setter- and getter-method names need to be as per the JavaBean guidelines (also called design patterns) for properties. If such a Java class is instantiable & manageable by the Spring IoC container, it is a Spring bean. To achieve this, the programmer wires the class as a bean definition of a suitable scope by using XML config files or annotations or a mix of both. The programmer can create new Spring beans out of existing Spring beans by wiring further by passing the latter to constructor-arguments of the former either as string-names as <idref>
elements or by dependency injection (it can be recursive).
This answer may be read in conjunction with my this SO answer to get more background information.

- 331
- 3
- 8