Skip to content

fix(sentinel): load classpath rule files from packaged JARs - #4396

Open
Rajandeep56 wants to merge 1 commit into
alibaba:2025.1.xfrom
Rajandeep56:2025.1.x
Open

fix(sentinel): load classpath rule files from packaged JARs#4396
Rajandeep56 wants to merge 1 commit into
alibaba:2025.1.xfrom
Rajandeep56:2025.1.x

Conversation

@Rajandeep56

Copy link
Copy Markdown

Describe what this PR does / why we need it

When Sentinel file rules are configured as a classpath resource (for example classpath:sentinel.json), the app works in an IDE but fails after java -jar with:
FileNotFoundException: class path resource [sentinel.json] cannot be resolved to absolute file path because it does not reside in the file system
FileDataSourceProperties.preCheck always converted the location with ResourceUtils.getFile(), which cannot resolve files packed inside a JAR.

Does this pull request fix one issue?

Fixes #462

Describe how you did it

If ResourceUtils.getFile() fails, load the Spring Resource as an InputStream and copy it to a temp file. FileRefreshableDataSource still receives a java.io.File, so filesystem files are unchanged.

Describe how to verify it

  1. Configure a file datasource, e.g. spring.cloud.sentinel.datasource.ds1.file.file=classpath:flowrule.json.
  2. Run from the IDE: rules load as before.
  3. Package the app and run java -jar. Startup should succeed and rules should load from the classpath file in the JAR.
  4. ./mvnw -pl spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource -am test

Special notes for reviews

JAR-packed rule files are copied to a temp file (deleteOnExit). They are not watched for live updates, which matches Sentinel’s assumption that files inside a JAR are immutable.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileNotFoundException throws when rules is provided by local resources in classpath and executed in command line

3 participants