【发布时间】:2018-04-12 07:26:24
【问题描述】:
我有以下 bean/构造函数定义:
@Configuration
class Configuration {
@Bean
public List<Something> getSomethings(MyFancyStuff stuff, @Autowired Bar bar) {
//...
}
}
@Component
class SomeOtherThing {
public SomeOtherThing(MyFancyStuff stuff, @Autowired Bar bar) {
//...
}
}
当找到给定参数的特定类或注释时,是否可以扩展依赖解析以提供自定义解析器?我查看了PropertyPlaceholderConfigurer 和InstantiationAwareBeanPostProcessor,但似乎没有什么可以帮助我编写自己的价值提供者。
作为上下文:我实现了一个自定义范围,它为它拥有的每个配置对象创建给定 bean 的许多实例。我想将此配置对象传递给所述范围的 bean-creation-process 而不将其添加到应用程序上下文中。我不想将它添加到应用程序上下文中,因为它是一个其他对象不应该能够通过依赖注入获得的对象。我需要扩展 spring 的 DI 过程,因为我想支持字段注入、构造函数注入和 bean 工厂方法,如所示 getSomethings
注意:这里不是关于 SpringMVC 请求参数的自动值转换。
【问题讨论】:
标签: java spring dependency-injection inversion-of-control