一、配置类,不能加@Configuration注解,否则报错
package cn.edu.tju.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.context.annotation.Configuration;
@ConfigurationProperties
@ConstructorBinding
public class AppConfig2 {
private String fristName;
private String lastName;
public AppConfig2(String firstName,String lastName){
this.fristName=firstName;
this.lastName=lastName;
}
public String getFristName() {
return fristName;
}
public void setFristName(String fristName) {
this.fristName = fristName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
二、启动类加@ConfigurationPropertiesScan注解或
@EnableConfigurationProperties(AppConfig2.class) 注解
package cn.edu.tju;
import cn.edu.tju.config.AppConfig2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
//@EnableConfigurationProperties(AppConfig2.class)
@ConfigurationPropertiesScan
public class Start {
public static void main(String[] args) {
//SpringApplication.run(Start.class,args);
SpringApplication springApplication=new SpringApplication(Start.class);
//springApplication.setEnvironmentPrefix("amadeus");
springApplication.run(args);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)