Skip to content
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

Servlet class loaded with the wrong class loader #506

Closed
Artur- opened this issue Feb 6, 2023 · 2 comments · Fixed by #550
Closed

Servlet class loaded with the wrong class loader #506

Artur- opened this issue Feb 6, 2023 · 2 comments · Fixed by #550
Milestone

Comments

@Artur-
Copy link
Contributor

Artur- commented Feb 6, 2023

Serverless Java Container version: 1.9.1

Implementations: Spring Boot 2

Framework version: SpringBoot 2.7.5

Frontend service: HTTP API

Deployment method: SAM

Scenario

A servlet class should be loaded by the application class loader. The current approach here loads it with the system class loader. This causes resource lookups inside a servlet to fail as the system class loader does not know anything about the resources on the application classpath.

Expected behavior

The system class loader is not used to load the servlet.

Actual behavior

The system class loader is used, is this what AwsServletContext.getClassLoader causes? Not sure why it would use the system class loader there. Can it just be changed?

@deki deki added this to the Release 2.0 milestone Feb 6, 2023
@deki
Copy link
Collaborator

deki commented Apr 27, 2023

@Artur- We are actively working on 2.0 right now which allows us to switch to a different classloader. Do you have a proposal?

Artur- added a commit to Artur-/aws-serverless-java-container that referenced this issue Apr 28, 2023
@Artur-
Copy link
Contributor Author

Artur- commented Apr 28, 2023

This seems to be what I used to get it to work

--- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java
+++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContext.java
@@ -545,9 +545,7 @@ public class AwsServletContext
 
     @Override
     public ClassLoader getClassLoader() {
-        // for the time being we return the default class loader. We may want to let developers override this int the
-        // future.
-        return ClassLoader.getSystemClassLoader();
+        return getClass().getClassLoader();
     }

Artur- added a commit to Artur-/aws-serverless-java-container that referenced this issue Apr 28, 2023
@deki deki closed this as completed in #550 Apr 28, 2023
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 a pull request may close this issue.

2 participants