您必须在主类中提及您要使用@ConfigurationProperties批注的类,如下所示。
@EnableConfigurationProperties(AppProperties.class)
具有@ConfigurationProperties的Property Configuration类将像这样
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "app")
public class AppProperties {
String name;
String id;
}
主班将是这样
import com.auth2.demo.config.AppProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(AppProperties.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}