Customized configuration parameters can override the default value through the application.properties file, but cannot override the default value through application.yml。
TcpServiceRegistrarConfigurationProperties
@Configuration
@ConfigurationProperties(prefix = CONFIG_PREFIX)
@Data
public class TcpServiceRegistrarConfigurationProperties {
public static final String CONFIG_PREFIX = "on.connect.service.registrar";
public static final String DEFAULT_REGISTRAR_BIND_IP = "127.0.0.1";
public static final int DEFAULT_REGISTRAR_BIND_PORT = 7000;
private String ip = DEFAULT_REGISTRAR_BIND_IP;
private int port = DEFAULT_REGISTRAR_BIND_PORT;
}
application.yml
on:
connect:
service:
registrar:
ip: localhost
port: 7002
server:
port: 8008
The customized parameters cannot override the default values, but server.port can.
application.properties
on.connect.service.registrar.port=7002
on.connect.service.registrar.ip=localhost
It can also be overridden through application.properties。
Comment From: hengboy
I use spring-boot v3.2.1 version
Comment From: hengboy
In the old version v2.7.x, this configuration can also override the default value
Comment From: wilkinsona
The YAML spec requires on to be converted to true. As a result, the properties defined in your YAML file are:
true.connect.service.registrar.iptrue.connect.service.registrar.portserver.port
This conversion is performed by SnakeYAML. It can be avoided by quoting the on key:
'on':
connect:
service:
registrar:
ip: localhost
port: 7002