Skip to content

Instantly share code, notes, and snippets.

@shinyay
Created June 12, 2021 11:28
Show Gist options
  • Select an option

  • Save shinyay/7cceda8742d5e8b0f554a6784ce0ebae to your computer and use it in GitHub Desktop.

Select an option

Save shinyay/7cceda8742d5e8b0f554a6784ce0ebae to your computer and use it in GitHub Desktop.

@ConfigurationProperties

src/main/resources/application.properties

app.config.app-name=Sample

src/main/java/*/properties/AppConfigProperties.java

@Getter
@Setter
@ConfigurationProperties(prefix = "app.config")
public class AppConfigProperties {
    private String appName;
}

src/main/java/*/service/AppService.java

@Service
public class AppService {
    @AutoWired
    private AppConfigProperties properties;

    public void test() {
        properties.getAppName(); // -> "Sample"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment