Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beans... what is it actually

Tags:

java

spring

What is a bean in spring framework? What is the use of the bean?

like image 605
Kevin Avatar asked May 07 '10 12:05

Kevin


People also ask

Are coffee beans beans or seeds?

Coffee beans are actually seeds inside of red or purple fruit called coffee cherries. They are not technically beans despite their resemblance to them. Seeds are considered beans only if they are part of the legumes family; however, the coffee tree is not one of them.

Is a bean a legume or a bean?

A bean can be a legume, but it will not be right to call legume beans. On the other hand, the beans are the Legume subsection, but you cannot call any beans Legumes. Legume owns various things in it. They can produce, plant growing seeds, beans, peas, lentils, and many other things.

Are beans good for You?

Perhaps the best quality about beans is that even the most novice chef can turn them into a delicious meal. There’s so much you can cook with beans using minimal kitchen skills. As if that wasn’t enough, beans have several health benefits; they’re high in fiber and protein and may help prevent disease. But first, are legumes beans?

What is the scientific name of beans?

We call them beans, but their scientific name is Phaseolus vulgaris (no surprise that beans became the prevalent term). Beans are a great source of protein and one of the most commonly eaten foods in the world. One of the great things about beans is that they cross cuisines; they’re a staple in many countries and cultures.


2 Answers

In the context of Spring, a bean is a managed object. What is a managed object? It's an object that Spring is aware of and that Spring knows how to manipulate, e.g. inject properties, invoke callback methods, etc.

There is then a difference between a regular java class (which Spring doesn't know about) and beans (which Spring knows about).

Generally Spring beans follow the Java bean convention, so that Spring can manipulate them easily. For instance if the bean is declared to have a property xxx, then Spring will expect getXxx and setXxx to be present. However, since Spring 2.X it is possible to dependency-inject private variables (using annotations), and therefore it is is no longer necessary to define a public setter in order to enable dependency injection for a property.

( The term bean is confusing in the sense that it is frequently uses to denote either (1) something that is managed by a container, like an enterprise java bean (EJB) or (2) something that adheres to the Java bean conventions. )

like image 92
ewernli Avatar answered Sep 20 '22 07:09

ewernli


The Java Bean spec does spell out no-arg constructor, getters/setters, and serializable, but Spring does not require that your beans follow the spec. Spring deals with Plain Old Java Objects, whether they conform to the Java Bean spec or not.

What's the use of beans? They express your wishes in code. All Spring is doing is managing their lifecycle and wiring them together to accomplish your goals.

like image 33
duffymo Avatar answered Sep 19 '22 07:09

duffymo