1

This question is not about escaping characters such as = or " in the property. The questions are:

  1. How do I get the expected values, e.g. for the password I want DE#F and not DE
  2. More academically; why is this happening?

(I assume) Spring is not reading in the environment variables correctly that contains an # in the string - on Linux. E.g.:

The yml file:

# Spring Boot configuration in yml file
application:
    username: Clark Kent
    password: abc

The overriding environmental variable in /etc/environment

APPLICATION_USERNAME="Ronald Raygan" #Maybe use a stronger password?
APPLICATION_PASSWORD="DE#F"

In the application, the following values are used:

@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {    
    private String username;
    private String password;
    // rest of the class
}

In another class:

System.out.println(applicationProperties.getUsername());
System.out.println(applicationProperties.getPassword());

This will print out:

Ronald Raygan"
DE
TungstenX
  • 830
  • 3
  • 19
  • 40
  • Possible duplicate of [How to escape the equals sign in properties files](https://stackoverflow.com/questions/2406975/how-to-escape-the-equals-sign-in-properties-files) – pvpkiran Jan 30 '18 at 08:36
  • what exactly is the question? – Stultuske Jan 30 '18 at 08:36
  • If you want quotes, probably you have to escape the character. The same thing for cardinal, because it's the character for comments. – voliveira89 Jan 30 '18 at 08:39
  • @pvpkiran Nope, I've tried escaping the text, I only end up with the \ in the property. e.g. `password="DE\#F"` gives me `DE\` (The \ is escaped in the String) – TungstenX Jan 31 '18 at 10:47
  • @Stultuske The question is: how to get the expected values, e.g `DE#F` and not `DE` – TungstenX Jan 31 '18 at 10:48
  • @voliveira89 nope don't want the quotes, I've also tried escaping the # but it doesn't work – TungstenX Jan 31 '18 at 10:49
  • @TungstenX # indicates comments in your properties files. meaning, you'll have to escape those. Not sure how, though – Stultuske Jan 31 '18 at 10:49
  • @Stultuske I've even tried to double escape the # e.g. `\\#` – TungstenX Jan 31 '18 at 11:27
  • that's how you escape in Java, but you're working in a propeties file. Check this: https://stackoverflow.com/questions/34605080/how-to-include-in-properties-file-escape-doesnt-work – Stultuske Jan 31 '18 at 12:12
  • Have you tried unicode escapes (eg `\u0023`)? – Mark Rotteveel Feb 01 '18 at 18:45

0 Answers0