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);
}
}
例
春は
public class AppServiceFactoryBean implements FactoryBean<AppService> {
public AppService getObject() throws Exception {
...
return appService:
}
public Class<?> getObjectType() {
return AppService.class;
}
}
springはgetoObject ()を自動的に呼び出します.
@Configuration
public class ServiceConfig {
@Bean
public AppServiceFactoryBean appService() {
return new AppServiceFactoryBean();
}
@Bean
public OtherService otherService(AppService appService) {
return new OtherService(appService);
}
}
例
春は
ファクトリーメソッドパターン
アイドル・ 9月29日・ 1分読む
#creational
#designpatterns
#java
#pattern
Reference
この問題について(Springのファクトリインタフェース), 我々は、より多くの情報をここで見つけました https://dev.to/eidher/spring-s-factorybean-interface-2c99テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol