Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inside spring-boot--application.yml- how to use special character #

Yaml file using # sign as comment

Comments in YAML look like this.

################
# SCALAR TYPES #
###############

Now inside properties file i have following value

root#

as password but yaml file using as comment , how can i skip it.

spring:
   #data source connection
  datasource:
    url: jdbc:mysql://localhost:3306/vaquarkhan
    username: rootadmin
    password: root#
like image 617
vaquar khan Avatar asked Jun 04 '18 00:06

vaquar khan


People also ask

How do you add special characters in yml?

YAML doesn't require quoting most strings but you'll want to quote special characters if they fall within a certain list of characters. Use quotes if your value includes any of the following special characters: { , } , [ , ] , & , * , # , ? , | , - , < , > , = , ! , % , @ , : also ` and , YAML Spec.

How do you escape the special characters in YAML?

When double quotes, "...." , go around a scalar string you use backslash ( \ ) for escaping, and you have to escape at least the backslash and the double quotes. In addition you can escape other special characters like linefeed ( \n ) and escape an end-of-line by preceding it by a backslash.


3 Answers

The list of special characters in YAML must be escaped.

:, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, `

You may either quote the string

"root#"

or use back slash.

root\#
like image 54
Pete T Avatar answered Oct 17 '22 21:10

Pete T


I think you can use quotation marks:

spring:
   #data source connection
  datasource:
    url: jdbc:mysql://localhost:3306/vaquarkhan
    username: rootadmin
    password: 'root#'
like image 35
Thiago Procaci Avatar answered Oct 17 '22 23:10

Thiago Procaci


This could be best way to do it.

  spring:
      #data source connection
        datasource:
          url: jdbc:mysql://localhost:3306/vaquarkhan
          username: rootadmin
          password: 'root#'
like image 2
Harshdev Singh Avatar answered Oct 17 '22 22:10

Harshdev Singh