I have a simple main app:
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = "dreamteam.eho")
@Import({EhoConfig.class})
public class MainApp implements CommandLineRunner, ApplicationContextAware {
With config:
@Configuration
@EnableConfigurationProperties({RootProperties.class})
public class EhoConfig {
}
And properties:
@ConfigurationProperties("root")
public class RootProperties {
private String name;
I try to load config:
--spring.config.location=file:///E:/.../eho-bot/props/ --spring.profiles.active=eho
Path is correct. But yml isn't loaded;
application-eho.yml file:
logging:
file: D:/java/projects/telegram-bots/eho.log
level:
dreamteam.eho: INFO
org.springframework: DEBUG
root:
name: EHO-BOT
App runs with args, but all props null. Logging properties not aplied; sout:
--spring.config.location=file:///E:.../eho-bot/props/
--spring.profiles.active=eho
--spring.output.ansi.enabled=always
For this moment you should use spring-boot.
@SpringBootApplication
public class ReTestsApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ReTestsApplication.class);
application.setWebEnvironment(false);
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
public void run(String... args) throws Exception {
}
}
Use webEnvironmet=false, and BannerMode=off (console application).
Docs, see https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-externalize-configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With