1、EnableConfigurationProperties

回顾属性装配

application.properties中添加

tomcat.host=192.168.2.1
tomcat.port=8080

增加属性类TomcatProperties

package com.lhx.spring.springboot_enable;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "tomcat")
public class TomcatProperties {
    private String host;
    private String port;

    public String getHost() {
        return host;
    }

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

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    @Override
    public String toString() {
        return "TomcatProperties [host=" + host + ", port=" + port + "]";
    }

}
View Code

相关文章:

  • 2021-08-28
  • 2021-08-23
  • 2021-07-04
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-08-18
猜你喜欢
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案