Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何动态地自动连线服务_Java_Spring Boot - Fatal编程技术网

Java 如何动态地自动连线服务

Java 如何动态地自动连线服务,java,spring-boot,Java,Spring Boot,我有一个像BaseService这样的接口,还有两个类CoreServiceImpl和TenantServiceImpl,它们都扩展了BaseService。现在我想在我的控制器中自动连接BaseService,如何通过传递任何参数来运行特定的服务(核心/租户?您可以使用@Profile: @Component @Profile("core") public class CoreServiceImpl {} @Component @Profile("tenant") public class

我有一个像BaseService这样的接口,还有两个类CoreServiceImpl和TenantServiceImpl,它们都扩展了BaseService。现在我想在我的控制器中自动连接BaseService,如何通过传递任何参数来运行特定的服务(核心/租户?

您可以使用
@Profile

@Component
@Profile("core")
public class CoreServiceImpl {}


@Component
@Profile("tenant")
public class TenantServiceImpl {}

然后使用
--spring.profiles.active=core/tenant运行spring

如果您能解释一下在哪一点上您想使用哪种OneHanks来获得所有支持,那会更好