APPLICATION.YML instances:
spring: redis: database: 0 host: 127.0.0.1
Get method:
/** *@Auther: Wangzibin *@Description: *@Modified by: */@ConfigurationPublicClassjedisconfig{Private Logger jedisconfiglogger= Loggerfactory.getlogger (jedisconfig.class); @Value ( "${spring.redis.host:#{null}}") private String host; @Value ( "${spring.redis.port:#{null}}") private Integer port; public String gethost () {return Host } public void setHost (String host) { this.host = host;} public Integer getport () {return Port } public void setPort (Integer Port) {this.port = port;}}
Note that @configuration annotations are required and @Component apply
@Value("${spring.redis.port:#{null}}")
which
:#{null}
Null assignment with default value when no corresponding configuration value is taken
Springboot to get the property values of the APPLICATION.YML configuration file through @value