DEV Community

eidher
eidher

Posted on • Updated on

Spring's FactoryBean Interface

interface FactoryBean<T> {
    public T getObject() throws Exception;
    public Class<?> getObjectType();
    public default boolean isSingleton() { return true; }
}
Enter fullscreen mode Exit fullscreen mode

Example

public class AppServiceFactoryBean implements FactoryBean<AppService> {
    public AppService getObject() throws Exception {
        ...
        return appService:
    }

    public Class<?> getObjectType() {
        return AppService.class;
    }
}
Enter fullscreen mode Exit fullscreen mode

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

Examples

Used in Spring by:

  • EmbeddedDatabaseFactoryBean
  • ProxyFactoryBean
  • JndiObjectFactoryBean
  • HibernateJpaSessionFactoryBean

Top comments (6)

Collapse
 
dabjazz profile image
Yash_Jaiswal

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.

Collapse
 
eidher profile image
eidher • Edited

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.

Collapse
 
dabjazz profile image
Yash_Jaiswal

Sir I would like to ask you few more questions.

  1. What are enterprise applications? Are they like websites build using html,css& JS at client side and any framework like django,rails at backend?
  2. How do I use java to learn back-end development? Apart from core java what are the other things I have to learn to begin backend development using java?
  3. How do I connect Spring with html,css,js frontend? Is is even possible? Is there any specific framework of java script that is compatible with spring ? Is spring framework is used for this?
  4. Does spring and django used for carrying out the same task i.e. Backend?
  5. Is spring boot is sufficient or do I need to learn different modules of spring?
  6. Lastly but not the least what kind of projects can I made after learning all this? Here all contains (html,css, js for frontend and spring for backend)
Thread Thread
 
eidher profile image
eidher
  1. Enterprise applications are software solutions that provide business logic and tools to model entire business processes independently of the technology used.
  2. I'd recommend to study java web.
  3. Using Spring MVC or REST Services
  4. Yes.
  5. I'd study other modules like Spring Security and Spring Data
  6. Follow spring.io/guides
Thread Thread
 
dabjazz profile image
Yash_Jaiswal

Thank you so much sir, for answering my questions.
I'll make sure to study java web, Spring MVC and REST services

Collapse
 
dabjazz profile image
Yash_Jaiswal

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πŸ™β˜•