javaspringpojospring-bean

Is a Spring Bean always a POJO?


Is it necessary that a Spring Bean always has to be a POJO?

Are there any other ways to create a bean which is not a POJO?


Solution

  • A Spring bean can be anything. Classes that can be instantiated normally (i.e. Java Beans or any other regular class) can be configured via xml or Java-Config.

    Anything that is more complicated can be created via a FactoryBean.

    So, to answer your question: Any Java object can become a Spring Bean.