亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述spring boot 读取 application.properties 初始化bean相关的知识,希望能为你提供帮助。
application.properties
bean1.hello = 你好~bean2.name= name bean2.title = titlebean3.info[name]= name bean3.info[title]= title bean3.info[age]= agebean4.info[0] = name0 bean4.info[1] = name1 bean4.info[2] = name2 bean4.info[3] = name3
BeanController
@RestController public class BeanController {@Value("${bean1.hello}") String bean1; @Resource Bean2 bean2; @Resource Bean3 bean3; @Resource Bean4 bean4; @RequestMapping("bean1") public String bean1() { return bean1; }@RequestMapping("bean2") public Bean2 bean2() { return bean2; }@RequestMapping("bean3") public Bean3 bean3() { return bean3; }@RequestMapping("bean4") public Bean4 bean4() { return bean4; }}
【spring boot 读取 application.properties 初始化bean】
Bean2.java
@ConfigurationProperties(prefix = "bean2") @Component public class Bean2 implements Serializable{ public String name; public String title; public String getName() { return name; }public void setName(String name) { this.name = name; }public String getTitle() { return title; }public void setTitle(String title) { this.title = title; } }
Bean3.java
@ConfigurationProperties(prefix = "bean3") @Component public class Bean3 implements Serializable{ private Map< String, String> info; public Map< String, String> getInfo() { return info; }public void setInfo(Map< String, String> info) { this.info = info; } }
Bean4.java
@ConfigurationProperties(prefix = "bean4") @Component public class Bean4 implements Serializable{ private List< String> info; public List< String> getInfo() { return info; }public void setInfo(List< String> info) { this.info = info; } }
推荐阅读
- spring data整合elasticsearch的applicationContext.xml文件模板
- [国家集训队2011]happiness(吴确) (最小割)
- Android 如何让EditText不自动获取焦点 (转)
- react native中Unable to load script from assets 'index.android.bundle'解决方案
- 通过adb命令在Android设备中执行Java命令, 并调用so文件。
- Android Studio - 第四十七期 毛玻璃效果以及动态生成二维码以及增大点击热区
- 最新Android平台的13款最佳离线赛车游戏推荐合集
- Android和iOS的13款最佳卡通图片编辑或滤镜应用程序合集
- 下载Torrent文件的12种最佳uTorrent替代软件推荐合集