java - @Service 没有从 jar 文件中注入
问题描述
我有一个运行大型企业应用程序的场景。
- 我有一个没有@SpringBootApplication 的应用程序,称为XYZ 应用程序。该应用程序没有在具有@SpringBootApplication 的ABC 应用程序中自动装配,我在Intellij 中运行它。如何确保在运行应用程序时创建了bean。
注意:我有 XYZ 应用程序的 jars 作为 gradle 构建。XYZ-api 和 XYZ-impl 有单独的 jars。
// XYZ-api
public interface LocationService{
}
//XYZ-impl
@Service("locationServiceImpl")
public class LocationServiceImpl implements LocationService{
@Resource
CountryDAO countryDAO;
}
//PQR (Some other jar file)
@Component
public class LocaleImpl implements Locale{
@Autowired
public LocationService locationService;
}
我得到的错误是“嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“localeImpl”的 bean 时出错:通过字段“locationService”表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“LocationService”类型的合格 bean:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)}"
我也尝试过包含 XYZ 应用程序的包,它确实解决了问题,但没有注入 @Resource CountryDAO bean。请帮忙。
解决方案
推荐阅读
- sql - 在事先不知道值的情况下将数组值分解为不同的列
- docker - 如何为已经使用 Nginx 运行 docker-compose 设置 certbot 证书?
- javascript - context.fillReact 不是函数
- python - 在 tkinter 中恢复输入以前的会话属性
- python - 使用 Onnx 转换 Sklearn 决策树后,有没有办法得到每个样本被预测为的叶子的索引?
- cvat - 如何从 CVAT 中的任务中删除作业
- angular - 如何配置 Spring Security 以避免 405 Method Not Allowed for PUT request from Angular?
- c - 按小数位对齐不同的数字长度浮动
- python - MAYA:对重复元素的父项进行编号
- c++ - C++中对象之间的相互引用