Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the difference between yml and properties in springboot

Shulou Source: shulou.com Published: 2022-06-02 11:08:04 09月27日 Update

This article introduces what is the difference between yml and properties in springboot. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Properties files need to be fully written, yml before the same can not be written, one layer corresponding to one layer is good.

By comparison:

Application.properties

Application.yml

There are some details to pay attention to in the yml file. The colon should be followed by a space before writing the value, although it will automatically be empty in the IDE.

What's the difference between an application.properties file and an application.yml file?

The benefits of yml files, the natural tree structure, are clear at a glance and are essentially similar to properties.

Many of the official demo are configured with yml files.

Note:

1. The original key, such as spring.jpa.properties.hibernate.dialect, press "." Split into tree-like configurations

The colon after the key must be followed by a space.

3. Delete the original application.properties. Then be sure to execute maven-X clean install

# application.ymlserver: port: 8086 spring: datasource: name: test url: jdbc:mysql://192.168.1.112:3306/test username: root password: xxx # use druid data source type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 MaxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20 applications. Propertiesserver.portalization8085spring.datasource.typeroomorg.apache.tomcat.jdbc.pool.DataSourcespring.datasource.urlroomjdbcjdbcdisplacement mysqldebartaliyuncs.compur3306Universe Unicodecodes trueworthy DateTimeBehaviorholders convertToNullroomautonectparts truespring.datasceour.usernameroomrootspring.datasource.passwordcards Class-name=com.mysql.jdbc.Driver#mybatis.mapper-locations=classpath*:com/wanyu/fams/mapping/*Mapper.xml#mybatis.type-aliases-package=com.wanyu.fams.modelspring.mvc.view.prefix=/WEB-INF/jsp/spring.mvc.view.suffix=.jspspring.druid.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.druid.datasource.driverClassName=com.mysql.jdbc.Driverspring.druid.datasource.url=jdbc:mysql://localhost:3306/spring_boot?characterEncoding=utf-8spring.druid.datasource.username=rootspring.druid.datasource.password=xxx

Although Spring Boot has done a lot of work to simplify the configuration, but its configuration is still quite complex!

As many as 17 external configurations are supported, which is flexible, of course, but flexibility means increased complexity.

Here we only talk about the priority of application.yml and application.properties files.

If there is an application.properties file in your project

Then the application.yml file is just a device.

Why would you say that?

I configured this in the application.properties file:

Server.port=8085

The following are configured in the application.yml file:

Server:

Port: 8086

Start the project, console output:

Main] s.b.c.e.t.TomcatEmbeddedServletContainer: Tomcat started on port (s): 8085 (http)

Fully illustrates this point.

This is the difference between yml and properties in springboot. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: File configuration complexity content colon more project one grid help yes same clear at a glance almost two priority interest just complexity natural benefit Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Apple Linux Redmi