我有一个简单的主应用程序:
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = "dreamteam.eho")
@Import({EhoConfig.class})
public class MainApp implements CommandLineRunner, ApplicationContextAware {
使用配置:
@Configuration
@EnableConfigurationProperties({RootProperties.class})
public class EhoConfig {
}
和属性:
@ConfigurationProperties("root")
public class RootProperties {
private String name;
我尝试加载配置:
--spring.config.location=file:///E:/.../eho-bot/props/ --spring.profiles.active=eho
路径正确。但是 yml 没有加载;
应用程序-eho.yml 文件:
logging:
file: D:/java/projects/telegram-bots/eho.log
level:
dreamteam.eho: INFO
org.springframework: DEBUG
root:
name: EHO-BOT
应用程序使用 args 运行,但所有道具都为空。未应用日志记录属性;苏:
--spring.config.location=file:///E:.../eho-bot/props/
--spring.profiles.active=eho
--spring.output.ansi.enabled=always
原文由 yazabara 发布,翻译遵循 CC BY-SA 4.0 许可协议
此时你应该使用 spring-boot。
使用 webEnvironmet=false 和 BannerMode=off(控制台应用程序)。
文档,请参阅 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-externalize-configuration