02. custom banner, global configuration file, @ Value for custom configuration, @ ConfigurationProperties, profiles configuration

Custom banner

  • New banner.txt under src / main / resource, the character is copied to banner.txt
  • Recommended sites generated characters:
    http://patorjk.com/software/taag
    https://www.bootschool.net/ascii

    Global configuration file

  • src / main / resource under the new application.yml or the application.properties
    the application.properties:
server.port=8090
# 以【localhost】/fly 开头
server.context-path=/fly
  • application.yml:
server:
  port: 8090

Read custom configuration - @ Value Gets

Defined application.properties

app.author=fly

Use @Value get

import org.springframework.beans.factory.annotation.Value;

  @Value("${app.author}")
    private String author;

Read custom configuration - @ ConfigurationProperties

import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "app")
public class xxx{
    private String author;
    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }
}

Configuration profiles

Spring.profiles.active disposed in the application.properties = dev will read the
application-dev.properties configuration

Guess you like

Origin www.cnblogs.com/fly-book/p/11563008.html