Spring Dependency Injection with Factory Method

By | June 18, 2021

In this post, We will learn about Spring Dependency Injection with Factory Method using a Demo Project.

Spring Dependency Injection with Factory Method:

In the Spring framework, if you want to create a bean by invoking a static factory-method, whose purpose is to encapsulate the object-creation process in a static method then you may use the factory-method attribute.

Now Let’s try to understand Spring Dependency Injection with Factory Method using the below demo Project. 

pom.xml

 

ATM.java

 

Printer.java

 

ApplicationContext.xml

 

ClientTest.java

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

The printer has printed the balance information of the account:109399390

That’s all about Spring Dependency Injection with Factory Method

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
getBean() overloaded methods in Spring Framework
Spring Inner bean example
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 *