-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Introduce registerResource(Resource) in ResourceHints #29083
Introduce registerResource(Resource) in ResourceHints #29083
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the proposal. I've added a few comments.
spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java
Show resolved
Hide resolved
spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java
Show resolved
Hide resolved
...est/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java
Show resolved
Hide resolved
@@ -92,4 +97,25 @@ public static void registerAnnotationIfNecessary(RuntimeHints hints, MergedAnnot | |||
} | |||
} | |||
|
|||
/** | |||
* Register that the supplied resource should be made available at runtime. | |||
* <p>If the supplied resource is not a {@link ClassPathResource}, it will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Or does not exist"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current Javadoc reads like this:
Determine if the supplied resource is a
ClassPathResource
that exists and register the resource for run-time availability accordingly.
Since getPath() returns a relative path if the resource was created using the ClassPathResource(String,Class) constructor, there was previously no way to consistently obtain the absolute path to the resource within the class path. This commit addresses this shortcoming by introducing a new getAbsolutePath() for consistently obtaining the absolute path to the resource within the class path. See spring-projectsgh-29083 Closes spring-projectsgh-29094
Reopening to switch back to the original method name and semantics. |
This commit throws an exception in registerResource() if the supplied resource is not a ClassPathResource. See gh-29083
Prior to this commit, the Javadoc for the getPath() method in ClassPathResource stated the following. > Return the path for this resource (as resource path within the class path). That implied the returned path was an "absolute path" within the class path; however, that was not always true. If the resource was created using ClassPathResource(String) or ClassPathResource(String, ClassLoader), the returned path was a cleaned version of the ABSOLUTE PATH supplied to the constructor, WITHOUT a leading slash. If the resource was created using ClassPathResource(String, Class) with an absolute path, the returned path was a cleaned version of the ABSOLUTE PATH supplied to the constructor, WITH a leading slash. If the resource was created using ClassPathResource(String, Class) with a relative path, the returned path was a cleaned version of the RELATIVE PATH supplied to the constructor. In addition, ClassPathResource does not provide public access the Class passed to the ClassPathResource(String, Class) constructor. Consequently, the path returned by getPath() could not be reliably used with ClassLoader.getResource(String) or with the recently introduced registerResource(Resource) method in ResourceHints. This commit addresses this issue by ensuring that getPath() consistently returns the absolute path within the class path without a leading slash. See spring-projectsgh-29083 Reverts spring-projectsgh-29094 Closes spring-projectsgh-29099
This PR simplifies the registration of hints for
classpath:
resources.