标签:main config ring cal tab public rop 方法 property
@SpringBootApplication
public class App {
public static void main(String[] args) {
ConfigurableApplicationContext context=SpringApplication.run(App.class, args);
//方法1: 直接使用AppicationContext.getEnvironment System.out.println(context.getEnvironment().getProperty("local.ip"));
context.getBean(UserConfig.class).show();
context.close();
}
}
@Component
public class UserConfig {
//方法3:注解获取
@Value("${local.port}")
private String localPort;
//方法2: 在配置类中注入Environment 使用.getProperties调用
@Autowired
private Environment env;
public void show() {
System.out.println("local.ip:"+env.getProperty("local.ip"));
System.out.println("local.port:"+localPort);
}
}
标签:main config ring cal tab public rop 方法 property
原文地址:https://www.cnblogs.com/qiqisx/p/9342956.html