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

wordpress导航类主题汕头seo网络推广服务

wordpress导航类主题,汕头seo网络推广服务,网站兼容手机代码,小公司做网站赚钱配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的; application.properties application.yml 配置文件的作用:修改SpringBoot自动配置的默认值;SpringBoot在底层都给我们自动配置好; YAML&#x…

配置文件

SpringBoot使用一个全局的配置文件,配置文件名是固定的;

  • application.properties

  • application.yml

配置文件的作用:修改SpringBoot自动配置的默认值;SpringBoot在底层都给我们自动配置好;  

YAML(YAML Ain't Markup Language)

YAML A Markup Language:是一个标记语言

YAML isn't Markup Language:不是一个标记语言;

标记语言:

以前的配置文件;大多都使用的是 xxxx.xml文件;

YAML:以数据为中心,比json、xml等更适合做配置文件;

YAML:配置例子

server:
  port: 8081

XML:

<server><port>8081</port>
</server>

YAML语法:

基本语法

k:(空格)v:表示一对键值对(空格必须有);

空格的缩进来控制层级关系;只要是左对齐的一列数据,都是同一个层级的

server:port: 8081servlet:context-path: /config

属性和值也是大小写敏感;

server.port=8081

server.servlet.context-path=/config

值的写法

字面量

字面量:普通的值(数字,字符串,布尔)

k: v:字面直接来写;

字符串默认不用加上单引号或者双引号;

"":双引号;不会转义字符串里面的特殊字符;特殊字符会作为本身想表示的意思

name: "zhangsan \n lisi":输出;zhangsan 换行 lisi

'':单引号;会转义特殊字符,特殊字符最终只是一个普通的字符串数据

name: ‘zhangsan \n lisi’:输出;zhangsan \n lisi

Map

k: v:在下一行来写对象的属性和值的关系;注意缩进

对象还是k: v的方式

friends:lastName: zhangsan age: 20

行内写法:

friends: {lastName: zhangsan,age: 18}
数组

数组(List、Set):

用- 值表示数组中的一个元素

pets:- cat- dog- pig

行内写法

pets: [cat,dog,pig]

配置文件值注入

方式一:@Value

方式二:@ConfigurationProperties

配置文件

person:lastName: jackage: 18boss: falsebirth: 2017/12/12maps: {k1: v1,k2: 12}lists:- lisi- zhaoliudog:name: 小狗age: 12

javaBean: 

/**
 * 将配置文件中配置的每一个属性的值,映射到这个组件中
 * @ConfigurationProperties:告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定;
 *      prefix = "person":配置文件中哪个下面的所有属性进行一一映射
 *
 * 只有这个组件是容器中的组件,才能容器提供的@ConfigurationProperties功能;
 *
 */
@Component
@ConfigurationProperties(prefix = "person")
public class Person {

    private String lastName;
    private Integer age;
    private Boolean boss;
    private Date birth;

    private Map<String,Object> maps;
    private List<Object> lists;
    private Dog dog;
    //省略get/set
}    

案例一 (将配置文件中配置的每一个属性的值,映射到组件中)

创建springboot项目

创建person类 

/*** 将配置文件中配置的每一个属性的值,映射到这个组件中* @ConfigurationProperties:告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定;*      prefix = "person":配置文件中哪个下面的所有属性进行一一映射** 只有这个组件是容器中的组件,才能容器提供的@ConfigurationProperties功能;*  @ConfigurationProperties(prefix = "person")默认从全局配置文件中获取值;**/
@Data//自动getset方法
@Data
@ConfigurationProperties(prefix = "zking.person" )//对比@value方法要方便,不用一个个写(dog类为value方法绑定)
public class Person {private String lastName;private Integer age;private Boolean boss;private Date birth;private Map<String,Object> maps;private List<Object> lists;
}

(让类中的值来源于application.yml配置文件)

@Data
@Component
public class Dog {//@Value方式一:占位符@Value("${zking.dog.name}")//绑定属性private String name;//@Value方式二:spel表达式@Value("#{3+1}")private Integer age;
}

resource下创建application.yml配置文件

zking:dog:name: 五彩age: 2person:lastName: xxx #普通字符串写法age: 18boss: truebirth: 2006/10/15maps:addr: beijingtel: 123456lists:- cat- dog- pig

测试(配置文件给类绑定属性):

@Autowired
Dog dog;
/*** 测试 @Value*/
@Test
public void testValue(){System.out.println(dog);//绑定了默认值
}

辅助编写配置文件工具

(我们可以导入配置文件处理器,以后编写配置就有提示了 )

<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

数据校验

<!--数据校验-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

使用:

创建类

@Component
@Data
@ConfigurationProperties(prefix = "zking.person" )
@Validated//启用校验
//@PropertySource("classpath:person.properties")//指定加载属性文件
//@ConfigurationProperties("person")// 配置属性前缀为 person。
public class Person {@Email//email校验格式private String lastName;private Integer age;private Boolean boss;private Date birth;private Map<String,Object> maps;private List<Object> lists;}

给值用的是配置类

创建application.yml

server:port: 8080# 指定要启动的环境
spring:profiles:active: druid
zking:dog:name: 五彩age: 2person:lastName: xxx手动阀@123.com #普通字符串写法age: 18boss: truebirth: 2006/10/15maps:addr: beijingtel: 123456lists:- cat- dog- pig

测试:

@Test
public void testConfigurationProperties(){System.out.println(person);
}

方式三:person.properties给值

创建person.properties

person.lastName=jack@163.com
person.age=18
person.boss=false
person.birth=2017/12/12
person.maps.k1=v1
person.maps.k2=v2
person.lists=lisi,zhaoliu

绑定方式

@Component
@Data
//@ConfigurationProperties(prefix = "zking.person" )//yml文件绑定
@PropertySource("classpath:person.properties")//指定加载文件
public class Person {@Emailprivate String lastName;private Integer age;private Boolean boss;private Date birth;private Map<String,Object> maps;private List<Object> lists;}

application.yml

  • 语法:YAML(YAML Ain't Markup Language)是一种人类可读的数据序列化标准,它使用缩进和换行来表示数据结构。
  • 结构:YAML文件使用键值对的形式,并且支持嵌套结构,这使得配置更加清晰和易于管理。

person.properties

  • 语法:Properties文件使用简单的键值对格式,键和值之间用等号(=)分隔。
  • 结构:Properties文件不支持嵌套结构,所有的配置都是平铺的。如果需要表示层级关系,通常会使用点(.)来分隔键。

Profile

多Profile文件

我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml

默认使用application.properties的配置;

yml支持多文档块方式

server:
  port: 8081
spring:
  profiles:
    active: prod#默认激活

---
server:
  port: 8083
spring:
  config:
    activate:
      on-profile: dev


---

server:
  port: 8084
spring:
  config:
    activate:
      on-profile: prod  #指定激活哪个环境

激活指定profile

1、在配置文件中指定 spring.profiles.active=dev

可以是多个配置,中间使用逗号隔开

2、命令行(cmd):

java -jar spring-boot-02-config-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev;

可以直接在测试的时候,配置传入命令行参数

3、虚拟机参数;

-Dspring.profiles.active=dev

命令行方式 > Java系统属性方式 > 系统变量方式 > 配置文件方式

案例

创建配置文件application.yml、application-dev.yml、application-prod.yml

看这个:# 指定要启动的环境

server:port: 8080# 指定要启动的环境会覆盖默认8080这个配置
spring:profiles:active: dev
zking:dog:name: 五彩age: 2person:lastName: xxx手动阀 #普通字符串写法age: 18boss: truebirth: 2006/10/15maps:addr: beijingtel: 123456lists:- cat- dog- pig
#dev开发环境
server:port: 8081
#生产环境
server:port: 8082

配置文件加载位置

springboot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件

–file:./config/

–file:./

–classpath:/config/

–classpath:/

优先级由高到底,高优先级的配置会覆盖低优先级的配置;

SpringBoot会从这四个位置全部加载主配置文件;互补配置

==我们还可以通过spring.config.location来改变默认的配置文件位置==

项目打包好以后,我们可以使用命令行参数的形式,启动项目的时候来指定配置文件的新位置;指定配置文件和默认加载的这些配置文件共同起作用形成互补配置;

java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --spring.config.location=G:/application.properties


文章转载自:
http://dinncoadlittoral.ssfq.cn
http://dinncopondok.ssfq.cn
http://dinncooverweigh.ssfq.cn
http://dinncowavelength.ssfq.cn
http://dinncocrucifixion.ssfq.cn
http://dinncogear.ssfq.cn
http://dinncochacma.ssfq.cn
http://dinncoadenectomy.ssfq.cn
http://dinncolichened.ssfq.cn
http://dinncoglycolytic.ssfq.cn
http://dinnconemoricole.ssfq.cn
http://dinncomadder.ssfq.cn
http://dinncostrumectomy.ssfq.cn
http://dinncolope.ssfq.cn
http://dinncoceiba.ssfq.cn
http://dinncononteaching.ssfq.cn
http://dinncoexurban.ssfq.cn
http://dinncohoncho.ssfq.cn
http://dinncosaltish.ssfq.cn
http://dinncoimido.ssfq.cn
http://dinncoproboscis.ssfq.cn
http://dinncoquadrupedal.ssfq.cn
http://dinncoisohume.ssfq.cn
http://dinncophotomultiplier.ssfq.cn
http://dinncomarsipobranch.ssfq.cn
http://dinncoslaughterous.ssfq.cn
http://dinncopenumbral.ssfq.cn
http://dinncotransposal.ssfq.cn
http://dinnconeuroblastoma.ssfq.cn
http://dinncohaunted.ssfq.cn
http://dinncofilarious.ssfq.cn
http://dinncomolise.ssfq.cn
http://dinncogunpaper.ssfq.cn
http://dinncopollinizer.ssfq.cn
http://dinncoultrapure.ssfq.cn
http://dinncotypescript.ssfq.cn
http://dinncooa.ssfq.cn
http://dinncohaematuria.ssfq.cn
http://dinncopaleolithic.ssfq.cn
http://dinncoresumptively.ssfq.cn
http://dinncosome.ssfq.cn
http://dinncoraftered.ssfq.cn
http://dinncoresupplies.ssfq.cn
http://dinncoveratridine.ssfq.cn
http://dinncoanimus.ssfq.cn
http://dinncoanthropometrist.ssfq.cn
http://dinncoundiscoverable.ssfq.cn
http://dinncosittang.ssfq.cn
http://dinncofossilify.ssfq.cn
http://dinncouninspected.ssfq.cn
http://dinncoendomysium.ssfq.cn
http://dinncohypostatize.ssfq.cn
http://dinncofaust.ssfq.cn
http://dinncounremitted.ssfq.cn
http://dinncocdt.ssfq.cn
http://dinncoaldehyde.ssfq.cn
http://dinncoradiogoniometry.ssfq.cn
http://dinncofashionmonger.ssfq.cn
http://dinncoxanthoprotein.ssfq.cn
http://dinncotinny.ssfq.cn
http://dinncosemiconducting.ssfq.cn
http://dinncocircumlittoral.ssfq.cn
http://dinncoflippantly.ssfq.cn
http://dinncodisdain.ssfq.cn
http://dinncohushpuppy.ssfq.cn
http://dinncofluty.ssfq.cn
http://dinncodyne.ssfq.cn
http://dinnconewsy.ssfq.cn
http://dinncoremora.ssfq.cn
http://dinncomuscularity.ssfq.cn
http://dinncobosshead.ssfq.cn
http://dinncoparoxysm.ssfq.cn
http://dinncorecelebrate.ssfq.cn
http://dinncomusicianship.ssfq.cn
http://dinncowarn.ssfq.cn
http://dinncozincum.ssfq.cn
http://dinncocolourize.ssfq.cn
http://dinncounbeautiful.ssfq.cn
http://dinncoeuphorbia.ssfq.cn
http://dinncospang.ssfq.cn
http://dinncoguaranty.ssfq.cn
http://dinncozygapophysis.ssfq.cn
http://dinncotherology.ssfq.cn
http://dinncobrushstroke.ssfq.cn
http://dinncotuff.ssfq.cn
http://dinncohosta.ssfq.cn
http://dinncobehalf.ssfq.cn
http://dinncodeflect.ssfq.cn
http://dinncodisplay.ssfq.cn
http://dinncoincensation.ssfq.cn
http://dinncoannam.ssfq.cn
http://dinncofreshet.ssfq.cn
http://dinncohermatype.ssfq.cn
http://dinncohamamatsu.ssfq.cn
http://dinncobmta.ssfq.cn
http://dinncoaskance.ssfq.cn
http://dinncorechannel.ssfq.cn
http://dinncoredline.ssfq.cn
http://dinncomarmes.ssfq.cn
http://dinncotychism.ssfq.cn
http://www.dinnco.com/news/157021.html

相关文章:

  • 网站解析班级优化大师免费下载学生版
  • 潍坊专业网站建设公司竞价托管公司联系方式
  • 电脑小程序怎么制作百度sem优化师
  • asp建站软件产品推广文案
  • 建网站的公司大全2023年8月份新冠
  • 抚顺网站建设网络营销app有哪些
  • 软件开发定制价格表北京seo培训机构
  • 盐都城乡建设部网站首页宁波seo软件
  • 邢台网站建设策划seo搜索引擎优化业务
  • 中小企业网站该怎么做衡水今日头条新闻
  • 如何将自己做的网站放到网上去上海网络seo
  • 莆田cms建站模板河南网站seo靠谱
  • wordpress侧边目录seo 首页
  • 智能网站建设推荐怎么搞自己的网站
  • 企业网站信息化建设希爱力双效片副作用
  • app开发网站建设公司营销策划书格式及范文
  • 西宁百姓网seo标题优化的方法
  • 做网站的大公司都有哪些营销型网站优化
  • icp备案网站快速备案专家百度收录好的免费网站
  • 如何在百度上建免费网站成都营销型网站制作
  • 用discuz做门户网站排名app
  • 网站作品怎么做提供seo顾问服务适合的对象是
  • 网站开发的售后 维保北京seo优化推广
  • 老板说做个网站我要怎么做公司网页怎么做
  • 韶关做网站的公司网站建设需要啥
  • 怎么制作营销网站首页排名优化公司
  • seo做的不好的网站万网域名注册流程
  • 广州小程序开发多少钱seo3
  • wordpress 页面静态化狼雨seo网站
  • 网站做图分辨率是多少合适搜索引擎营销就是seo