Application. Yml instance:

spring:
    redis:
      database: 0
      host: 127.0. 01.
Copy the code

Obtaining method:



/ * * *@Auther:WangZiBin
 * @Description:
 * @Modified By:
 */
@Configuration
public class JedisConfig{

    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(a) {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort(a) {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port; }}Copy the code

Note that the @Configuration annotation is required, as is the @Component annotation

@Value("${spring.redis.port:#{null}}")
Copy the code

Among them

: # {null}
Copy the code

If the corresponding configuration value cannot be obtained, the default value is NULL

I am aDying strandedI am always looking forward to meeting you. Whether you expect it or not, tides come and go, I’m just here…

See you next time