您好,登錄后才能下訂單哦!
開始...
1、首先創(chuàng)建一個maven工程,引入springboot依賴
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--熱部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</dependencies>
2、編寫啟動springboot的啟動類
@SpringBootApplication
public class SpringbootApp {
public static void main(String[] args) {
SpringApplication.run(SpringbootApp.class, args);
}
}
3、編寫一個可訪問的Controller,該類可以獲取application.yml文件中的變量
application.yml內(nèi)容
server:
port: 9001
spring:
profiles:
active: linux
@Controller
public class HelloController {
@Autowired
ApplicationContext applicationContext;
@GetMapping(value = "/hello")
@ResponseBody
public String hello(){
return applicationContext.getEnvironment().getProperty("server.port");
}
}
4、在瀏覽器輸入地址http://localhost:9001/hello
頁面顯示9001
...結(jié)束
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。