interface FactoryBean<T> {
public T getObject() throws Exception;
public Class<?> getObjectType();
public default boolean isSingleton() { return true; }
}
Example
public class AppServiceFactoryBean implements FactoryBean<AppService> {
public AppService getObject() throws Exception {
...
return appService:
}
public Class<?> getObjectType() {
return AppService.class;
}
}
FactoryBeans with Java Configuration:
Spring calls getObject() automatically.
@Configuration
public class ServiceConfig {
@Bean
public AppServiceFactoryBean appService() {
return new AppServiceFactoryBean();
}
@Bean
public OtherService otherService(AppService appService) {
return new OtherService(appService);
}
}
Examples
Used in Spring by:
- EmbeddedDatabaseFactoryBean
- ProxyFactoryBean
- JndiObjectFactoryBean
- HibernateJpaSessionFactoryBean
Top comments (6)
Sir, I would like to know what spring framework is used for?
What are the differences between spring boot and spring?
What are the prerequisites for learning spring?
Can you go through this roadmap and correct or provide some extra things
Core java->advance java (JSP, Servlets, JDBC)->build tool(Maven or Gradle)->framework (Spring/Hibernate/Play)
Also what is EJB and J2EE are they same or there is a difference?
How do I become a Java developer?
I know these are a lot of questions but I need an experience java developer to answer these.
Spring Framework is a container for building Java Enterprise Applications facilitating some tasks that in pure Java are cumbersome. Your objects do not have to worry about finding or connecting each other because Spring instantiates and dependency injects your objects. Spring Boot handles the most low-level setup for you. For learning Spring you need to know Java. Your roadmap makes sense. EJB is which Spring came to replace. J2EE is a Java version that contains EJB. I became a Java developer thanks to my first job but I had some knowledge from the University.
Sir I would like to ask you few more questions.
Thank you so much sir, for answering my questions.
I'll make sure to study java web, Spring MVC and REST services
Thank you Sir for your time and answering my questions. It makes my roadmap clear and also clears out many uncertainties required to achieve my goal🙏☕