newToScala
newToScala

Reputation: 407

Spring Boot YAML Config w/ unique file name

I am trying to read in a simple yml file for a Spring Boot application located at resources/wtf.yml. The following application works if the default application.yml filename is used, but not if I change the filename. Anyone know why this doesn't work?

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import javax.annotation.PostConstruct;

@EnableConfigurationProperties
@SpringBootApplication
@ConfigurationProperties(locations = {"wtf.yml"}) //classpath:wtf.yml
public class SomeApp {

  public static void main(final String[] args) {
    SpringApplication.run(SomeApp.class, args);
  }

  @PostConstruct
  public void init() {
    System.out.println(readTimeout);
  }

  @Value("${readTimeout}")
  public int readTimeout;
}

Upvotes: 3

Views: 4323

Answers (1)

Piotr Jagielski
Piotr Jagielski

Reputation: 368

You can use spring.config.name or spring.config.location properties as described in Spring Boot guide.

Upvotes: 1

Related Questions