您需要定义一个将Bean
@Configuration构建
SomeFactory为Bean的类:
@Configurationclass SomeFactoryConfiguration { @Bean public ServiceFactory serviceFactory() { return new ServiceFactory(): }}
这将在您的Spring应用程序中将此ServiceFactory实例公开为Bean,您可以简单地自动装配。
如果愿意,也可以将ServiceA和ServiceB创建为Bean,然后在创建ServiceFactory时引用它们:
@Configurationclass SomeFactoryConfiguration { @Bean public ServiceFactory serviceFactory() { return new ServiceFactory(serviceA(), serviceB()): } @Bean public ServiceA serviceA() { return new ServiceA(); } @Bean public ServiceB serviceB() { return new ServiceB(); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)