Description
Several days ago on Stack Overflow I asked the related question, "spring.config.import: relative file path with vs without file: prefix?". I've had no answer.
I'm raising this issue here not as a question, but as either a docs enhancement request or a bug report, depending on whether the Spring Boot developers characterize the difference in behavior (details below) as a feature or a bug.
I'd planned to wait for answers on Stack Overflow and then, depending on those answers, possibly raise an issue here. However (acknowledging this is my problem), I'm on a tight schedule: I'm writing the user documentation for a Spring Boot application, and I want to know whether/how to document using spring.config.import
to refer to a relative file path without a file:
prefix.
Difference in behavior
I've recently been caught out by the difference that the file:
prefix makes to a relative file path for spring.config.import
.
In practice, it seems to be the case that:
- With a
file:
prefix, a relative file path is relative to the current working directory - Without a
file:
prefix, a relative file path is relative to the file that containsspring.config.import
For example, given the following current working directory (that is, where config
is a child directory of the current working directory):
config/
application.yaml
application-import.yaml
(In case anyone's wondering: yes, I'm familiar with profiles, and typically prefer them to spring.config.import
.)
In application.yaml
, to import application-import.yaml
, I can specify either:
spring:
config:
import: file:./config/application-import.yaml # relative to current working directory
or:
spring:
config:
import: ./application-import.yaml # relative to application.yaml
This issue: docs enhancement request or bug report
The nature of this issue depends on whether the Spring Boot developers characterize this difference in behavior as a feature (working by design) or a bug:
- Feature: this issue is a docs enhancement request. Please enhance the Spring Boot docs to mention this difference in behavior under the heading "Importing Additional Data".
- Bug: this issue is a bug report. Please fix it; that is, so that there is no difference in the behavior of
spring.config.import
for a relative file path with vs without thefile:
prefix.
Related Spring Boot docs
I've looked for, but not found, information in the Spring Boot docs about specifying the location of a configuration properties file (such as application-import.yaml
) as a relative path in the file system with a file:
prefix versus without a file:
prefix. If I've missed it, please point me to it.
It occurred to me that the Spring Boot developers and docs writers might say, "In the context of spring.config.*
properties, all references to file system paths should be explicitly prefixed by file:
. We deliberately don't document the behavior without that prefix."
But then, I found this counterexample in the 2020 Spring blog post "Config file processing in Spring Boot 2.4":
Import definitions use URL-like syntax as their value. If your location doesn’t have a prefix, it’s considered to be a regular file or folder.
So, the Spring Boot developers have explicitly considered the behavior for locations without a prefix. But, there's no mention of the difference in behavior between specifying a relative file path with or without a file:
prefix.
Related Spring Framework docs
The "underlying" Spring Framework docs topic "Core Technologies / Resources" contains related information about specifying a file path with or without a file:
prefix, but, understandably in that relatively low-level context, it's fairly general. For example:
When such a location path does not have a prefix, the specific
Resource
type built from that path and used to load the bean definitions depends on and is appropriate to the specific application context.
"appropriate to the specific application context" makes sense in the context of those relatively low-level Spring Framework docs, but it isn't much help to a user of the "higher-level" Spring Boot spring.config.import
property.
If this difference in behavior is a feature and not a bug, then, unless I'm missing something in the Spring Boot docs, I suggest that the Spring Boot docs description of spring.config.import
ought to explicitly describe this particular "appropriate to the specific application context" behavior.