我正在使用Spring Boot,并有两个非常相似的服务,我想在其中配置application.yml。
配置大致如下所示:
serviceA.url=abc.com
serviceA.port=80
serviceB.url=def.com
serviceB.port=8080
Run Code Online (Sandbox Code Playgroud)
是否可以创建一个注有注释的类@ConfigurationProperties并在注入点设置前缀?
例如
@Component
@ConfigurationProperties
public class ServiceProperties {
private String url;
private String port;
// Getters & Setters
}
Run Code Online (Sandbox Code Playgroud)
然后在服务本身中:
public class ServiceA {
@Autowired
@SomeFancyAnnotationToSetPrefix(prefix="serviceA")
private ServiceProperties serviceAProperties;
// ....
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我没有在文档中找到有关此功能的任何信息...非常感谢您的帮助!