java - 自定义属性文件在较低的项目层中读取为实体
问题描述
我想使用我的自定义属性类。我的项目 hiearcy 像这样,每个都是不同的项目。
我可以在 mycontroller 项目中使用带有 Autowired 注释的 ConfigurationProperties,但是当我在我的 dao 项目中尝试它时,自动装配的 myproperties 为空。
-MyController-->Autowired myproperties ok
-MyService
-MyDAO-->Autowired myproperties 为空
@Component
//@Configuration
@PropertySource("classpath:my.properties")
@ConfigurationProperties public class MyProperties {
我想在我的底层项目中使用我的自定义属性文件作为对象。
在我的 dao 层中,我可以读取自定义属性文件,例如键值,但我想将其作为实体读取。
prop = new Properties();
String filename = "my.properties";
input = MyProperties.class.getClassLoader().getResourceAsStream(filename);
prop.load(input);
Enumeration<?> e = prop.propertyNames();
while (e.hasMoreElements()) {....
解决方案
推荐阅读
- python-3.x - 使用 Python 3.7 云函数并行写入 Firestore
- python - 使用scrapy删除空数据
- c++ - 是否可以向 Win32Gui 中的 WindowProcedure 发送自定义消息?
- flutter - 在 buildContext 空间中使用连字符来抖动某些情况
- visual-studio-code - 有没有办法在 VS Code 控制台中正确获取孟加拉字体?
- java - java.lang.ClassCastException: java.math.cannot be cast to java.lang.Long 同时启动服务器
- python - 带有热型重量的 XY 图
- haskell - 如何在 emacs 中对齐函数参数的 Haddock 注释?
- android - 使用显示/隐藏事务保存片段状态是否错误?
- android - 仅更新当前的 viewpager 片段