Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
具有相同bean名称的Spring启动测试多个项目_Spring_Spring Boot_Spring Mvc - Fatal编程技术网

具有相同bean名称的Spring启动测试多个项目

具有相同bean名称的Spring启动测试多个项目,spring,spring-boot,spring-mvc,Spring,Spring Boot,Spring Mvc,我有多个spring项目作为一个伞式项目的一部分。其中两个是AuthServer和BackendApplicationAuthServer,顾名思义,仅用于身份验证目的,其余部分由BackendApplication处理。现在我正在尝试在BackendApplication中编写测试,这些测试也需要使用与auth相关的工作。为此,我添加了AuthServer作为BackendApplication的测试依赖项。现在的问题是,这两个项目都有bean名称实用程序,因此当我在测试中包括这两个上下文时,

我有多个spring项目作为一个伞式项目的一部分。其中两个是
AuthServer
BackendApplication
AuthServer
,顾名思义,仅用于身份验证目的,其余部分由
BackendApplication
处理。现在我正在尝试在
BackendApplication
中编写测试,这些测试也需要使用与auth相关的工作。为此,我添加了
AuthServer
作为
BackendApplication
的测试依赖项。现在的问题是,这两个项目都有bean名称
实用程序
,因此当我在测试中包括这两个上下文时,我会得到DuplicateBeanException。但我可以禁用其中任何一个,因为它们是必要的。有办法吗?

你能给你的豆子命名吗,例如:

@Bean(name = "my-utility-1")
public Utility createUtility1() {
  return new Utility();
}

// or

@Component(value = "my-utility-2")
public class Utility {
  ...
}
并通过@Qualified引用它们

@Autowired @Qualified("my-utility-1")
private Utility myUtility;
与您的问题无关,但我认为您可以在测试
后端应用程序时模拟
AuthServer