getBean() overloaded methods in Spring Framework

By | June 22, 2021

In this post, We will learn about the getBean() overloaded methods in Spring Framework Example using a Demo Project.

Spring BeanFactory has the following five getBean() Overloaded methods:

  1. Object getBean(String name) throws BeansException;
  2. <T> T getBean(Class<T> requiredType) throws BeansException;
  3. <T> T getBean(Class<T> requiredType, Object… args) throws BeansException;
  4. <T> T getBean(String name, Class<T> requiredType) throws BeansException;
  5. Object getBean(String name, Object… args) throws BeansException;

Now Let’s try to understand the above getBean() overloaded methods using the below demo Project.

pom.xml

Employee.java

Java Class which is registered as Spring bean in Spring Container.

Address.java

applicationContext.xml

Spring bean XML Config file. 

ClientTest.java

Client Program with the main method.

If you run ClientTest.java as Java Application then it will give the below output: 

That’s all about getBean() overloaded methods in Spring Framework Example

You May Also Like:

Spring BeanFactory Container Example
Spring ApplicationContext Container Example
Annotation-based Configuration in Spring Framework Example
Spring Java-based Configuration Example
Spring Setter Dependency Injection Example
Spring @Autowired Annotation With Setter Injection Example
Spring Constructor based Dependency Injection Example
Spring @Autowired Annotation With Constructor Injection Example
Spring Autowiring byName & byType Example
Spring Inner bean example
Spring Dependency Injection with Factory Method
Spring Framework @Qualifier example
Injecting Collections in Spring Framework Example
Spring Bean Definition Inheritance Example
Spring bean scopes with example
Spring JSR-250 Annotations with Example
Spring BeanPostProcessor Example
Spring JDBC Integration Example
Spring JDBC Annotation Example
Spring with Jdbc java based configuration example
Spring JDBC NamedParameterJdbcTemplate Example
How to call stored procedures in the Spring Framework?

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *