当前位置: 首页 > news >正文

七台河哈尔滨网站建设广州高端网站建设

七台河哈尔滨网站建设,广州高端网站建设,网站制作流程分为哪三步,杭州萧山网站开发2019独角兽企业重金招聘Python工程师标准 今天这篇文章给大家介绍自定义配置的两种方式 第一式#xff1a; 使用ConfigurationProperties#xff0c;且看代码 package com.developlee.customconfig.config;import org.springframework.boot.context.properties… 2019独角兽企业重金招聘Python工程师标准 今天这篇文章给大家介绍自定义配置的两种方式 第一式 使用ConfigurationProperties且看代码 package com.developlee.customconfig.config;import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.context.annotation.Configuration;/*** author Lensen* desc* since 2018/8/22 12:59*/ Configuration ConfigurationProperties(prefix one-app) public class OneAppConfig {NestedConfigurationPropertypublic Account account new Account();public String appName;public Account getAccount() {return account;}public void setAccount(Account account) {this.account account;}public String getAppName() {return appName;}public void setAppName(String appName) {this.appName appName;}public class Account {private String username;private String password;private String age;public String getUsername() {return username;}public void setUsername(String username) {this.username username;}public String getPassword() {return password;}public void setPassword(String password) {this.password password;}public String getAge() {return age;}public void setAge(String age) {this.age age;}} }很明显这就是我们要在properties文件中要配置的配置项。 再看第二种方式 /*** author Lensen* desc* since 2018/8/22 13:19*/ Configuration public class TwoAppConfig {Value(${two-app.welcome.message})public String twoAppWelcomeMessage;Value(${two-app.welcome.person})public String twoAppWelcomePerson;public String getTwoAppWelcomeMessage() {return twoAppWelcomeMessage;}public void setTwoAppWelcomeMessage(String twoAppWelcomeMessage) {this.twoAppWelcomeMessage twoAppWelcomeMessage;}public String getTwoAppWelcomePerson() {return twoAppWelcomePerson;}public void setTwoAppWelcomePerson(String twoAppWelcomePerson) {this.twoAppWelcomePerson twoAppWelcomePerson;} }这个就简单粗暴啦。没有第一种方式结构那么清晰具体怎么使用完全取决于项目配置项的关联关系和复杂度需要大家根据实际情况权衡。 接下来我写了个简单的测试类来获取我们的配置信息 先看配置文件 one-app:app-name: OneAPPaccount:username: Lensenpassword: Orclage: 22two-app:welcome:message: welcome to lensens bolgperson: LENSEN一个简单的Controller类 package com.developlee.customconfig.controller;import com.developlee.customconfig.config.OneAppConfig; import com.developlee.customconfig.config.TwoAppConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;/*** author Lensen* desc* since 2018/8/22 16:40*/ RestController public class AppController {Autowiredprivate OneAppConfig oneAppConfig;Autowiredprivate TwoAppConfig twoAppConfig;GetMapping(/hello)public ResponseEntity getConfig() {String str1 oneAppConfig: oneAppConfig.getAppName() oneAppConfig.getAccount().getUsername() oneAppConfig.getAccount().getPassword() oneAppConfig.getAccount().getAge();String str2 twoAppConfig: twoAppConfig.getTwoAppWelcomePerson() twoAppConfig.getTwoAppWelcomeMessage();return new ResponseEntity(str1 ~~~~~~~ str2, HttpStatus.OK);} }在地址栏输入http:localhost:8080/hello, 回车 也可以自己指定文件只需在类上加上注解PropertySource注解就好了~~ Configuration PropertySource(classpath:my.properties) public class ThreeConfig {Value(${my.name})private String myName;public String getMyName() {return myName;}public void setMyName(String myName) {this.myName myName;} }my.properties文件内容 my.namedeveloplee测试结果 如果配置文件是yml格式的则要使用YamlPropertiesFactoryBean来加载并设置到PropertySourcesPlaceholderConfigurer中 // 加载YML格式自定义配置文件Beanpublic static PropertySourcesPlaceholderConfigurer properties() {PropertySourcesPlaceholderConfigurer configurer new PropertySourcesPlaceholderConfigurer();YamlPropertiesFactoryBean yaml new YamlPropertiesFactoryBean();yaml.setResources(new FileSystemResource(config.yml));//File引入 // yaml.setResources(new ClassPathResource(youryml.yml));//class引入configurer.setProperties(yaml.getObject());return configurer;end... 浮躁的社会浮躁的人生唯有代码宁静致远。又开始装13了,见谅..... 最后以上示例代码可在我的github.com中找到。 我的个人公众号developlee的潇洒人生。 关注了也不一定更新更新就不得了了。 转载于:https://my.oschina.net/liululee/blog/2250330
http://www.yutouwan.com/news/340605/

相关文章:

  • 网站建设仿站企业公司网页版百度云
  • 在网站做登记表备案 如果修改wordpress关键词在哪里设置
  • 有没有人做网站高端产业主要指哪些领域
  • 厦门网站开发wordpress 更新用户名
  • 工会网站建设方案长春网站制作优势吉网传媒
  • 做网站导航的响应式网站和营销型网站
  • ps做网站的分辨率多少施工企业发展的建议
  • 公司网站备案名称建设大型网站的公司
  • 百度搜索什么关键词能搜到网站网站ui设计是什么
  • 兴文移动网站建设福建永安建设局网站
  • 网站建设公司名字上海企业服务云代表啥
  • 做文创的网站爱南宁app下载
  • 旅游网站界面设计制作微信小程序步骤
  • 鄂州网站建设与设计泉州建设公司网站的公司
  • 网站设计实施方案如何自己弄一个网站
  • 网站的会员功能怎么做仿网站源码
  • 快手做任务网站高性能网站建设指南在线阅读
  • 网页模板下载哪个网站好重庆百度竞价排名
  • 网站 免费 托管运营江苏省建设安全协会网站
  • 上海做家庭影院的公司网站做外贸怎样浏览国外网站
  • 创意网站建设话术wordpress作者信息插件
  • 网站伪静态设置怎么做网站上的模拟动画
  • 昌平网站建设浩森宇特上海商标设计
  • wordpress 网站名称中企动力网站建设 医疗
  • 不会做网站能做网络销售吗四川企业seo
  • 网站建设公司网站制作网站建设分解结构
  • 网站程序源码下载8网站免费建站
  • 成品网页网站网站设计二级页面怎么做
  • 品牌网站建设保障大蝌蚪品牌建设的最高境界是培育客户成为
  • 聊城专业建网站价格酒店网站 asp.net