【发布时间】:2019-01-24 13:22:54
【问题描述】:
我想在生产中动态注入类。假设我们有一个 Shape 接口,它提供了 Rectangle 和 Triangle 这两个类的实现。
对于某些类,我想提供 Triangle 实例,而对于某些类,我想提供一个 Rectangle 类实例。
所以问题是如何在 Spring Boot 中做到这一点
interface Shape{
}
class Rectangle implements Shape{
}
class Triangel implements Shape{
}
【问题讨论】:
-
Spring boot 与 Java 相同,这是您的问题吗?
-
你不用强制使用spring容器,你可以自己创建实例
-
你可以选择
@Qualifier或@Profile或@Conditional..you can find @condition here。
标签: spring-boot