java - 将属性中的值注入接口字段
问题描述
是否有在接口字段上插入属性的选项?我尝试过这样的事情,但没有奏效。
public interface ServicePathsConfig {
@Value("${default-connection-timeout}")
int DEFAULT_CONNECT_TIMEOUT = 1000;
}
我尝试使用@PostConstruct 制作默认设置器,结果相同。任何想法如何将属性注入接口字段?
解决方案
您可以使用此代码打开配置 java 类。@Configuration @ComponentScan("com.??") @PropertySource("classpath:(??.properties"))
并将 default-connection-tiemout 放到另一个没有 int 的新属性文件中。但是你不能把它注入到你需要注入一些java类的接口中。
推荐阅读
- lisp - Common Lisp - type checking two variables
- c# - 是否有可能摆脱这种 Nuget Hell 情景?
- java - 与替换 Java 的组合
- netbeans - 如何让 NetBeans 8.0.2 拼写检查器提出更正建议?
- javascript - Uploading CVS file to server along with user input data
- visual-studio - 能否将 Service Fabric 应用程序从 Windows Docker 容器内部署到群集?
- node.js - Mongoose can't find my data from database but database has been connected
- java - static library load of OpenCV causing app crash
- powershell - 将参数嵌入开关
- matrix - Why spatial transformer network (STN) is not working on image