New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The '$' character in the application.properties parameter name is forcibly deleted #23238
Comments
Thanks for the report. The need to wrap the key in square brackets ( |
Please clarify that. The report was raised for version 2.2.8 of spring boot and indeed it seems that requires the '[..]' to escape. However spring boot 2.3.3 are the docs you actually linked to and from my experiments at least, it doesn't seem like there is a need to escape in this particular example. The doc also seems to be talking about maps in yaml not .properties file which I think follow a different set of rules. So this is all leaving me a little confused. |
Escaping should be required in 2.3.3 and my own experimentation shows that's the case: package com.example.demo;
import java.util.Properties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(ExampleProperties.class)
public class Gh23238Application {
public static void main(String[] args) {
Properties properties = SpringApplication.run(Gh23238Application.class, args)
.getBean(ExampleProperties.class).getProperties();
System.out.println(properties);
}
}
@ConfigurationProperties("example")
class ExampleProperties {
private final Properties properties = new Properties();
public Properties getProperties() {
return properties;
}
}
Note that
That section of the docs isn't specific to YAML and the small snippet of YAML is only an example. The only YAML-specific part in that section is in the tip that notes the need to use quotes:
|
Thanks for the clarification. I cannot reproduce the example from yesterday anymore. So not sure what happened. Anyway, I guess the safe thing to do would be to always use '[..]' since that seems to work most reliably even if there might be some odd cases where it works without, this is not something to be relied on. I would suggest a few possible improvements to the docs:
|
This is already largely covered in the section on using YAML instead of properties. Elsewhere, and as done here, we call out additional differences where relevant. In the interests of not making the documentation overly verbose, I think this strikes a good balance. I'm not keen on explicitly stating that there are no other differences everywhere. We would have to do it consistently to avoid causing confusion and doing so would add significantly to the length of the documentation.
Yep, this needs to be clarified. Escaping them does no harm but it also isn't (always) necessary. I've opened #23390.
Hopefully this is already covered in the section on using YAML instead of properties. |
Yes, agreed. Thanks for pointing that out. @wilkinsona Of course you have the final say on which of my suggestions you consider useful to act on (that should go without saying, but I'm saying it anyway to be clear).
I agree. The docs are pretty good really. But, even if you don't want to change any of the explanation... I still would like to see an extra example of a .properties equivalent to the yml example that is already there. Just seeing that example there would have probably avoided some confusion to me personally (i.e avoided my lazy brain from jumping to the wrong conclusion that the section is only about yml). |
We'd like to do that across the board. I've opened #23515. |
Problem
I'll do it again application.properties Is configured in
spring.datasource.hikari.data-source-properties.v$session.program=myapp
, but the final property key isvsession.program
.spring.datasource.hikari.data-source-properties
is a java.util.Properties,v$session.program
As a property key is completely legal, so I think it is a bug.Finally, I use the following configuration to get the correct property key
spring.datasource.hikari.data-source-properties[v$session.program]=myapp
But only problem is that the spring boot language server prompts an error as follows
Can't use '[..]' navigation for property 'spring.datasource.hikari.data-source-properties' of type java.util.Properties
Environment
The text was updated successfully, but these errors were encountered: