This page looks best with JavaScript enabled

springboot使用@value 获取yml配置中的值

 ·  ☕ 1 min read

https://github.com/JohntunLiu/course-online

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
@SpringBootApplication
@EnableEurekaServer
@Slf4j
public class EurekaApplication {
//	private static final Logger LOG = LoggerFactory.getLogger(EurekaApplication.class);

	private static String port2;

	//获取port值
	@Value("${server.port}")
	public  String port;

	@PostConstruct
	public void getPort() {
		port2=this.port;
	}

	public static void main(String[] args) {
		SpringApplication.run(EurekaApplication.class, args);
		log.info("启动成功!!");
		log.info("Eureka地址: \thttp://127.0.0.1:"+port2);
	}
Support the author with
alipay QR Code
wechat QR Code