Go to file
Sam Brannen 03ae97b2eb Introduce Spring property for default escape character for placeholders
Spring Framework 6.2 introduced support for an escape character for
property placeholders (by default '\'). However, as of Spring Framework
6.2.6, there was no way to either escape the escape character or disable
escape character support.

For example, given a `username` property configured with the value of
`Jane.Smith` and a `DOMAIN\${username}` configuration string, property
placeholder replacement used to result in `DOMAIN\Jane.Smith` prior to
6.2 but now results in `DOMAIN${username}`. Similarly, an attempt to
escape the escape character via `DOMAIN\\${username}` results in
`DOMAIN\${username}`.

In theory, one should be able to disable use of an escape character
altogether, and that is currently possible by invoking
setEscapeCharacter(null) on AbstractPropertyResolver and
PlaceholderConfigurerSupport (the superclass of
PropertySourcesPlaceholderConfigurer).

However, in reality, there are two hurdles.

- As of 6.2.6, an invocation of setEscapeCharacter(null) on a
  PropertySourcesPlaceholderConfigurer applied to its internal
  top-level PropertySourcesPropertyResolver but not to any nested
  PropertySourcesPropertyResolver, which means that the `null` escape
  character could not be effectively applied.

- Users may not have an easy way to explicitly set the escape character
  to `null` for a PropertyResolver or
  PropertySourcesPlaceholderConfigurer. For example, Spring Boot
  auto-configures a PropertySourcesPlaceholderConfigurer with the
  default escape character enabled.

This first issue above has recently been addressed by gh-34861.

This commit therefore addresses the second issue as follows.

- To allow developers to easily revert to the pre-6.2 behavior without
  changes to code or configuration strings, this commit introduces a
  `spring.placeholder.escapeCharacter.default` property for use with
  SpringProperties which globally sets the default escape character that
  is automatically configured in AbstractPropertyResolver and
  PlaceholderConfigurerSupport.

- Setting the property to an empty string sets the default escape
  character to `null`, effectively disabling the default support for
  escape characters.

    spring.placeholder.escapeCharacter.default =

- Setting the property to any other character sets the default escape
  character to that specific character.

    spring.placeholder.escapeCharacter.default = ~

- Setting the property to a string containing more than one character
  results in an exception.

- Developers are still able to configure an explicit escape character
  in AbstractPropertyResolver and PlaceholderConfigurerSupport if they
  choose to do so.

- Third-party components that wish to rely on the same feature can
  invoke AbstractPropertyResolver.getDefaultEscapeCharacter() to obtain
  the globally configured default escape character.

See gh-9628
See gh-34315
See gh-34861
Closes gh-34865
2025-05-13 13:37:30 +02:00
.github
.idea
buildSrc Upgrade spring-javaformat-gradle-plugin to version 0.0.43 2025-04-27 16:51:47 +02:00
framework-api Fail Gradle build whenever a javadoc task fails 2025-04-27 17:59:41 +02:00
framework-bom
framework-docs Introduce Spring property for default escape character for placeholders 2025-05-13 13:37:30 +02:00
framework-platform
gradle Fail Gradle build whenever a javadoc task fails 2025-04-27 17:59:41 +02:00
integration-tests
spring-aop
spring-aspects
spring-beans Introduce Spring property for default escape character for placeholders 2025-05-13 13:37:30 +02:00
spring-context Introduce Spring property for default escape character for placeholders 2025-05-13 13:37:30 +02:00
spring-context-indexer
spring-context-support
spring-core Introduce Spring property for default escape character for placeholders 2025-05-13 13:37:30 +02:00
spring-core-test
spring-expression
spring-instrument
spring-jcl
spring-jdbc
spring-jms
spring-messaging
spring-orm
spring-oxm
spring-r2dbc Properly expand reused collection parameters in R2DBC NamedParameterUtils 2025-05-09 14:27:19 +02:00
spring-test Ensure Bean Overrides are discovered once in hierarchies 2025-05-02 11:26:33 +02:00
spring-tx
spring-web Fix HttpClient 5.3.x request config compatibility 2025-05-05 14:38:30 +02:00
spring-webflux Ensure Fragment can merge attributes 2025-05-02 15:58:51 +01:00
spring-webmvc
spring-websocket
src
.editorconfig
.gitattributes
.gitignore
.sdkmanrc
CONTRIBUTING.md
LICENSE.txt
README.md
SECURITY.md
build.gradle
gradle.properties
gradlew Upgrade to Gradle 8.14 2025-04-27 16:29:46 +02:00
gradlew.bat Upgrade to Gradle 8.14 2025-04-27 16:29:46 +02:00
import-into-eclipse.md
import-into-idea.md
settings.gradle
update_copyright_headers.sh

README.md

Spring Framework Build Status Revved up by Develocity

This is the home of the Spring Framework: the foundation for all Spring projects. Collectively the Spring Framework and the family of Spring projects are often referred to simply as "Spring".

Spring provides everything required beyond the Java programming language for creating enterprise applications for a wide range of scenarios and architectures. Please read the Overview section of the reference documentation for a more complete introduction.

Code of Conduct

This project is governed by the Spring Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to spring-code-of-conduct@spring.io.

Access to Binaries

For access to artifacts or a distribution zip, see the Spring Framework Artifacts wiki page.

Documentation

The Spring Framework maintains reference documentation (published and source), GitHub wiki pages, and an API reference. There are also guides and tutorials across Spring projects.

Micro-Benchmarks

See the Micro-Benchmarks wiki page.

Build from Source

See the Build from Source wiki page and the CONTRIBUTING.md file.

Continuous Integration Builds

Information regarding CI builds can be found in the Spring Framework Concourse pipeline documentation.

Stay in Touch

Follow @SpringCentral, @SpringFramework, and its team members on 𝕏. In-depth articles can be found at The Spring Blog, and releases are announced via our releases feed.

License

The Spring Framework is released under version 2.0 of the Apache License.