让我用代码来演示:
public interface A {
....
}
@Profile({"V1"})
@Component
public class B implements A {
....
}
@Profile({"V2"})
@Component
public class C implements A {
....
}
我如何动态地(在每个到达的请求上)让 spring 根据它们的配置文件 Autowiring 上述类之一?甚至可以在接线时做这样的事情吗?
背景:我正在寻求实现服务器端版本控制机制的良好实践。如果请求属于版本“V1”,我想 Autowiring 一个具有“V1”配置文件的类,反之亦然。 (目前我正在 Autowiring 一个列表并迭代它们以找到合适的版本)。
最佳答案
is it even possible to autowire bean in every request?
不,这不可能。在创建上下文时注入(inject) Bean。
I am seeking a good practice to implement server side version control mechanism
关于java - 如何在 Spring Autowiring 具有特定配置文件的实现者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30010503/