SpringBoot打包,SpringBoot之使用(一)

 2023-10-05 阅读 30 评论 0

摘要:2019獨角獸企業重金招聘Python工程師標準>>> 今天用SpringBoot的框架寫了一小段Java程序,在此簡單寫一下。 SpringBoot版本 <version>2.1.0.RELEASE</version> SpringBoot打包、1.使用application.yml 自定義參數 operate:file:input: D:/input.

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

今天用SpringBoot的框架寫了一小段Java程序,在此簡單寫一下。

SpringBoot版本

<version>2.1.0.RELEASE</version>

SpringBoot打包、1.使用application.yml 自定義參數

operate:file:input: D:/input.txt

2.實現類中調用配置參數

因為只是簡單的java程序并且有一兩個方法,調用配置文件中的屬性因此使用@component注解

@ConfigurationProperties(prefix = "operate")? 使用自定義的屬性

@Slf4j
@Component
//親測這塊注釋也能正常運行 @ConfigurationProperties(prefix = "operate")
public class Test {@Value("${operate.file.input}")private String inputPath;public void operate() {log.info("input path {}",inputPath);}
}

SpringBoot商城、3. Application中調用定義好的類

@SpringBootApplication
@Slf4j
public class TestApplication {public static void main(String[] args) {ConfigurableApplicationContext run = SpringApplication.run(TestApplication.class, args);Test bean = run.getBean(Test.class);bean.operate();}}

?

這樣就實現了Java類的簡單調用。

?

Springboot框架、轉載于:https://my.oschina.net/u/2329222/blog/2876301

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/117767.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息