第二步:创建配置属性类HelloProperties
```package com.laoyang.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
- @author:Kevin
- @create: 2022-09-17 09:27
@Description: 创建数据源配置类,用于封装配置文件的配置属性
*/
@ConfigurationProperties(prefix = "hello")
public class HelloProties {private String name;
private String adress;public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String toString() {return "HelloProties{" + "name='" + name + '\'' + ", adress='" + adress + '\'' + '}';
}
}第二步:创建配置属性类HelloProperties
package com.laoyang.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
- @author:Kevin
- @create: 2022-09-17 09:27
@Description: 创建数据源配置类,用于封装配置文件的配置属性
*/
@ConfigurationProperties(prefix = "hello")
public class HelloProties {private String name;
private String adress;public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String toString() {return "HelloProties{" + "name='" + name + '\'' + ", adress='" + adress + '\'' + '}';
}
}第三步:创建服务类HelloService
package com.laoyang.service;
/**
- @author:Kevin
- @create: 2022-09-17 09:34
- @Description: 服务类
*/
public class HelloService {
private String name;
private String address;
public HelloService(String name, String address) {
this.name = name;
this.address = address;
}
public String sayHello(){
return "你好!我的名字叫 " + name + ",我来自 " + address;
}
}
```