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

柯桥区建设集团网站制作手机端网站

柯桥区建设集团网站,制作手机端网站,wordpress爆路径,温州网站建设怎么样配置的概念#xff1a; Spring Boot是基于约定的#xff0c;所以很多配置都有默认值#xff0c;但如果想使用自己的配置替换默认配置的话#xff0c;就可以使用application.properties或者application.yml(application.yaml)进行配置。 注意配置文件的命名必须是applicat…配置的概念 Spring Boot是基于约定的所以很多配置都有默认值但如果想使用自己的配置替换默认配置的话就可以使用application.properties或者application.yml(application.yaml)进行配置。 注意配置文件的命名必须是application开头。 优先顺序 在同一级目录下优先级为properties yml yaml 内部配置优先顺序 file:../config/ 当前项目下的/config目录 file:../ 当前项目的根目录 classpath:/config/classpath的/config目录 classpath:/ classpath的根目录 java和resources的文件会被打包到classes的目录 properties和yml实际上会被打包到classpath路径下 即优先级顺序如图 外部配置优先顺序 https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config properties、xml、yml格式比对 properties server.port8080 server.address127.0.0.1 xml: serverport8080/portaddress127.0.0.1/address /server yml: server:port:8080address:127.0.0.1 Yamlyml 大小写有区别数据前必须有空格空格数目无所谓作为分隔符否则不识别该数据。缩进的空格数目不重要但是相同层级的元素要左对齐。注释的话快捷键也是ctrl/是#空格。参数引用的话用${}包裹起来即可。 对象(map)键值对的集合 person:name: zhangsan# 行内写法 person: {name: zhangsan} 数组 address:- beijing- shanghai # 行内写法address: [beijing,shanghai] 纯量单个的、不可再分的值。一般都是字符串 msg1: hello \n world # 单引忽略转义字符 msg2: hello \n world # 双引识别转义字符 读取配置内容 Value application.yml的对象用到几个就要注入几个。 application.yml中 server:port: 8082name: abcPerson:name: zhangsanage: 20Student:name: ${name} # 占位符表示abc那个name会传输到这里address:- beijing- shanghaimsg1: hello \n world # 不会识别转义字符 msg2: hello \n world # 会识别转义字符 HelloController中 package com.example.springini.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class HelloController {Value(${name})//和application.yml的键值对的键要同名与下一行的私有成员名字无关private String nname;Value(${Person.name})private String name2;Value(${Person.age})private int age;Value(${Student.name})private String name3;Value(${address[0]})private String addr;Value(${msg1})private String msg11;Value(${msg2})private String msg22;RequestMapping(/hello2)public String hello2(){System.out.println(nname);System.out.println(name2);System.out.println(name3);System.out.println(age);return hello springboot;}RequestMapping(/hello)public String hello(){System.out.println(addr);System.out.println(msg11);System.out.println(msg22);return hello springboot;} } AutowiredEnvironment 将application.yml一次性作为一个对象全都注入。 HelloController中 package com.example.springini.controller;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class HelloController_by_environment {Autowiredprivate Environment env;RequestMapping(/hello)public void hello(){System.out.println(env.getProperty(name));System.out.println(env.getProperty(Person.name));System.out.println(env.getProperty(address[0]));System.out.println(env.getProperty(msg1));System.out.println(env.getProperty(msg2));}} AutowiredConfigurationProperties 将配置内容与对象相互绑定。 新建Person类中 package com.example.springini;import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Component //表示这个Person类被识别成BeanConfigurationProperties(prefix person) //如果不指定prefix为person那么它不一定找到配置文件的person底下的两个字段name和age //而可能去找到单独的两个字段name和age。public class Person {private String name;//命名必须和yml文件中的键值对的键保持一致private int age;public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;} } HelloController中 package com.example.springini.controller;import com.example.springini.Person; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class HelloController_by_ConfigurationProperties {Autowiredprivate Person p;RequestMapping(/hello)public void hello(){System.out.println(p.getName() : p.getAge());}} profile动态配置切换 我们在开发Spring Boot应用时通常同一套程序会被安装到不同环境比如开发、测试、生产等。其中数据库地址、服务器端口等等配置都不同如果每次打包时都要修改配置文件那么非常麻烦。profile功能就是来进行动态配置切换的。 配置方式 多profile文件方式 application-dev.properties/yml  开发环境application-test.properties/yml  测试环境application-pro.properties/yml   生产环境 yml多文档方式 在yml中使用----分隔不同配置 激活方式 配置文件 在配置文件中配置spring.profiles.activedev 虞拟机参数 在VM options指定-Dspring.profiles.activedev 命令行参数 java-jar xxx.jar --spring.profiles.activedev
http://www.yutouwan.com/news/376366/

相关文章:

  • 郑州网站建设学习免费广告发布平台
  • 做打鱼网站犯法不郑州网站制作网
  • 北京欢迎你 网站建设成都网站建设低价
  • 如何熟悉网站项目的逻辑网站开发专业前景
  • 咸阳企业网站设计开发制作怎么在vps上建网站
  • 网站开发工具推荐织梦网站地图模板修改
  • 天猫优惠卷怎么做网站企业免费发布信息平台
  • 油画网站模板山东省住房和城市建设厅网站
  • 网站html静态化解决方案与狗狗做网站
  • 用dw做网站怎么上传到网站上西安小程序搭建
  • 黑龙江建设监理协会网站建网站需要了解什么
  • 容桂医疗网站建设什么装修网站做的好的
  • 青海网站制作公司chaincd wordpress
  • 公司建设网站的优缺点网站开发 项目接单
  • 长图制作网站网站公司市场营销方案
  • 如何做一家门户网站icp备案流程
  • 郴州建网站计算机软件开发就业前景
  • 网站加入百度广告联盟甘肃多元网络
  • 六安网站关键词排名优化报价企业网站模板网页模板
  • 网站管理和维护的主要工作有哪些科技公司网站推荐
  • 手机看黄山网站拉新注册app拿佣金
  • wordpress电影主题会员排名优化工具
  • 为中小型企业构建网站东莞桂城网站制作
  • 上杭网站设计公司电商网站建设成本
  • vs做网站怎么把网页改为自适应大小电子商务网站推广方案
  • 甘肃白银住房建设局网站福州营销型网站建设价格
  • 怎么做网站收录的关键词乐清市住房和城乡建设规划局网站
  • 怎么建设物流网站网站建设与策划
  • 上海建立公司网站西安网站建设资讯
  • 学校文化建设的网站园林绿化网站建设