Springのファクトリインタフェース


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


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

    public Class<?> getObjectType() {
        return AppService.class;
    }
}

Java構成のファクトリ


springはgetoObject ()を自動的に呼び出します.
@Configuration
public class ServiceConfig {

    @Bean
    public AppServiceFactoryBean appService() {
        return new AppServiceFactoryBean();
    }

    @Bean
    public OtherService otherService(AppService appService) {
        return new OtherService(appService);
    }
}


春は
  • 埋込みデータベース
  • Proxyfactorybean
  • jndiObjectFacizyBean