Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot doesn't load application.yml config

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
like image 919
yazabara Avatar asked Apr 21 '16 06:04

yazabara


1 Answers

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

like image 95
yazabara Avatar answered Oct 13 '22 17:10

yazabara