Scrivio Interview library
ScenarioAdvanced5 min read · updated 12 November 2026

Templates, reports and reference files are loaded from the classpath, the file system and HTTP URLs in different services, and a missing file once broke production. How would you standardise resource loading?

I would set four rules. Static resources that change with the code are packaged inside the application jar and read from the classpath. External resources come from one defined location per service, configured by properties rather than hard-coded paths. Required resources are checked at startup, so a missing file stops the deployment instead of breaking a request. Remote resources are never fetched on the request path without timeouts and caching, and all code uses Spring's Resource and ResourceLoader instead of raw File, Paths or URL APIs, so the location can change without code changes.

Why this question is asked

When services load templates from the classpath, reports from a mounted folder and reference files from an HTTP URL, each in its own way, nobody can tell from the outside what a service needs to run. A file is renamed, a volume is not mounted in one environment, or a remote server is slow, and the failure shows up only when a user asks for a report. That is what happened in this scenario, and the question is how to prevent the whole class of failure. Interviewers ask it to see whether we can turn one incident into a simple, enforceable standard. In this answer, we will classify the resources, decide where each kind lives, make missing resources fail at startup, handle remote resources safely, and use one API everywhere.

1Classifying the Resources

The first step is to ask, for each resource, when it changes. Some resources change together with the code: an email template whose placeholders match the code, a report layout, a JSON schema. Others change on their own schedule: a reference list of postal codes updated monthly, a customer-specific branding file, a large dataset maintained by another team. The first kind belongs to the release; the second kind belongs to the environment.

This classification decides everything else. A template that must match the code should never come from a shared folder where someone can update it independently, and a monthly data file should not require a rebuild to change.

Where each kind of resource lives
Kind of resourceWhere it livesHow it is read
Changes with the code (templates, schemas)inside the jarclasspath: location
Changes per environment (branding, keys)mounted volume or configfile: location from a property
Maintained by another team, largeobject store or HTTPfetched with timeout, cached locally
Secretssecret manager or mounted secretnever in the jar or a public URL

2One Configured Location per Service

External resources should not be scattered across hard-coded paths such as /opt/reports in one class and /data/ref in another. Each service declares its resource locations in configuration properties, with sensible defaults, so operations can see and change them in one place. Spring converts the location strings to Resource objects for us, and because the prefix decides where to look, the same code can read from the classpath in tests and from a mounted folder in production.

Java
@ConfigurationProperties("acme.resources")
@Validated
public record ResourceProperties(
@NotNull Resource invoiceTemplate, // classpath:templates/invoice.html by default
@NotNull Resource postalCodes) { } // file:/data/ref/postal-codes.csv in production
# application.yml
acme.resources.invoice-template: classpath:templates/invoice.html
acme.resources.postal-codes: ${POSTAL_CODES_LOCATION:classpath:ref/postal-codes-sample.csv}

Notice that a Resource field can be bound directly from a string; Boot's conversion service turns classpath: and file: locations into Resource objects.

3Failing at Startup When Something Is Missing

The production incident happened because a missing file was discovered at the first request. The fix is to check required resources when the application starts. A Resource object exists even when the file behind it does not, so we must call exists(), and ideally read the content once to prove it is usable.

Java
@Component
class RequiredResourcesCheck implements InitializingBean {
private final ResourceProperties props;
RequiredResourcesCheck(ResourceProperties props) { this.props = props; }
@Override
public void afterPropertiesSet() {
for (Resource r : List.of(props.invoiceTemplate(), props.postalCodes())) {
if (!r.exists() || !r.isReadable()) {
throw new IllegalStateException("Required resource missing: " + r.getDescription());
}
}
}
}
// Missing file -> context refresh fails -> the pod never becomes ready -> the old version keeps serving
Step throughWhat happens to a deployment with a missing file
  1. New version startsbinds acme.resources
  2. Check required resourcesexists() and readable
  3. All present?
    YesContext ready, pod receives trafficNoStartup fails with a clear message
  4. Rolling update stops on failureold version keeps serving
  5. Fix the mount or propertyredeploy

5 steps in order. Play them, or step through them one at a time.

Because the new version never becomes ready, a rolling deployment stops and the previous version keeps serving traffic. A configuration mistake becomes a failed deployment, which is cheap, instead of a failed request, which a customer sees.

4Handling Remote Resources Safely

Remote resources are the riskiest. Spring can read a UrlResource from an http: location, but it uses a plain URL connection that has no timeouts by default, so a slow server can hang the request thread indefinitely. Loading such a resource on every request also multiplies the load on the remote server and makes our latency depend on it.

So the rule is: never fetch a remote resource on the request path without a timeout and a cache. Better still, fetch it at startup or on a schedule with an HTTP client that has connect and read timeouts, keep the last good copy in memory or on local disk, and serve from that copy. If the refresh fails, we keep using the last good version and raise an alert, rather than failing user requests.

5One API Everywhere

Finally, all code uses Spring's Resource and ResourceLoader rather than new File(...), Paths.get(...) or new URL(...).openStream(). The Resource abstraction reads the same way from the classpath, the file system and URLs, it works inside a Boot jar, where a classpath resource is not a file, and it lets the location change by configuration alone. A shared library can add a small helper for reading text with UTF-8 and a static analysis rule can flag raw File access to resource folders, so the standard is enforced by the build, not only by a wiki page.

6Follow-up questions

Should templates ever be loaded from outside the jar?

Only when they really change independently of the code, for example customer branding managed by another team. Even then the code and template must agree on placeholders, so I would version the templates and validate them at startup, for example by rendering a sample with test data.

How do you test the startup check?

With a Spring Boot test that sets the location property to a path that does not exist and asserts that the context fails to start with our message. ApplicationContextRunner makes this quick, since it starts a small context and lets us assert on the failure.

What about very large files?

Do not read them into memory at startup. Check that they exist and are readable, then stream them with getInputStream() when needed, or load them into a database or index as part of a separate import job.

7Conclusion

In this answer, we standardised resource loading by classifying resources by when they change: those that change with the code live in the jar, external ones come from a single property-configured location, and secrets come from a secret store. Required resources are checked at startup so a missing file fails the deployment rather than a request, remote resources are fetched with timeouts and cached, and every service uses Resource and ResourceLoader instead of raw file APIs.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by classifying resources by when they change. Anything that changes with the code, like templates, report layouts and schemas, gets packaged in the application jar and read from a classpath location, so a release always has matching code and templates.

Then, if they want more

Things that change per environment or on their own schedule come from one defined location per service, configured in properties, so operations can see what a service needs, and the same code reads a sample from the classpath in tests and a mounted file in production.

Because the production incident came from a missing file found at the first request, every required resource is checked at startup: I bind them as Resource properties and verify exists and isReadable in an initialisation check, so a missing file fails the context, the pod never becomes ready, and the rolling deployment stops with the old version still serving.

Remote resources are never fetched on the request path without timeouts and caching, since Spring's UrlResource has no timeouts by default. I would fetch them at startup or on a schedule with a proper HTTP client, keep the last good copy, and alert if refreshing fails.

Finally, everyone uses Resource and ResourceLoader instead of File or Paths, which works inside a Boot jar and lets the location change by configuration alone.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Templates, reports and reference files are loaded from the classpath, the file system...": https://scrivio-interview-library.netlify.app/spring-boot/spring-utilities/145d9a220d/