java - 在配置文件之间切换以管理一个弹簧接口上的多个实现
问题描述
我正在尝试使用具有不同配置文件的 Spring 接口的不同实现。我有多个模块在不同的模块中有代码。接口和 2 个实现在一个模块中,调用接口的类在不同的模块中。我的代码是这样的:
从模块1:
public class FirstService {
@Autowired
private Interface interfaceImplementation;
}
从模块2:
public interface Interface {
}
@Service
@Profile("develop")
public class InterfaceImpl1 implements Interface {
}
@Service
@Profile("test")
public class InterfaceImpl2 implements Interface {
}
当我启动我的应用程序时,应用程序无法启动并出现以下错误:
Field interface in FirstService required a bean of type Interface that could not be found
谢谢您的帮助。
解决方案
我能够通过将接口的基本包(位于单独模块中的实现)添加到应用程序中的 @ComponentScan 来解决此问题。
推荐阅读
- python - 如何使用opencv实现gimp之类的高光和白点调整功能?
- git - 如何从 git 的所有分支中删除名为 .css 的文件
- python - 如何从python中的主脚本退出多处理池进程中的while循环
- r - Imports 字段中的命名空间不是从:'rlang''shinydashboard' 导入的,我应该写 @importFrom rlang rlang 还是 @importFrom rlang
- flutter - Flutter - 无法识别的应用程序。请确保您信任此应用程序,然后再继续
- asp.net - 文件上传未检测到文件扩展名
- sql - 使用 generate_series() 删除行范围?
- android - 防止请求重放攻击
- date - 在嵌套的 IFS 语句中保留 Google 表格中的日期格式
- pspice - 如何解决在 ltspice 的错误日志中发现的问题?