Skip to content

[Spring Boot 3.2.0] 404 Not Found behavior #38733

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

Closed
infoShare opened this issue Dec 11, 2023 · 6 comments
Closed

[Spring Boot 3.2.0] 404 Not Found behavior #38733

infoShare opened this issue Dec 11, 2023 · 6 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@infoShare
Copy link

404 Not found behavior was changed during upgrade from 3.1.6 to 3.2.0.

Previous behavior
404 Not found error returned:

{
    "timestamp": "2023-12-11T13:26:38.174+00:00",
    "status": 404,
    "error": "Not Found",
    "path": "/api/method"
}

Current behavior:
NoResourceFoundException thrown with message "No static resource api/method." thrown.

Here you can find small example:
https://github.com/infoShare/code-examples/tree/main/spring-boot-404

Test ApiControllerWithProfileTest is passing on spring boot 3.1.6

[INFO] Results:
[INFO] 
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

but failing on spring boot 3.2.0:

[ERROR] Failures: 
[ERROR]   ApiControllerWithProfileTest.executeMethod:40 
expected: 404 NOT_FOUND
 but was: 500 INTERNAL_SERVER_ERROR
[INFO] 
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 11, 2023
@mhalbritter
Copy link
Contributor

mhalbritter commented Dec 11, 2023

Starting with Spring Framework 6.1 (which Boot 3.2.0 uses), NoResourceFoundException is thrown if there's no handler. This exception is handled by your infoshare.springboot404.handler.GlobalExceptionHandler#globalExceptionHandler and translated to a HTTP 500.

See here for more details: https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#web-applications or this issue spring-projects/spring-framework#29491.

@mhalbritter mhalbritter added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 11, 2023
@mhalbritter mhalbritter closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
@BruceAn1978
Copy link

BruceAn1978 commented Dec 14, 2023

Starting with Spring Framework 6.1 (which Boot 3.2.0 uses), NoResourceFoundException is thrown if there's no handler. This exception is handled by your infoshare.springboot404.handler.GlobalExceptionHandler#globalExceptionHandler and translated to a HTTP 500.

See here for more details: https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#web-applications or this issue spring-projects/spring-framework#29491.

No any exceptions throwed under no any ExceptionHandler configed (version: 3.1.5).

@mhalbritter
Copy link
Contributor

mhalbritter commented Dec 14, 2023

I don't understand. What's the expected outcome and what does happen? Also Boot 3.1.5 doesn't use Spring Framework 6.1.0.

@BruceAn1978
Copy link

BruceAn1978 commented Dec 15, 2023

I have not configure any global ExceptionHandler, a json responsed like below and no any exception was threw on server sider:
{ "timestamp": "2023-12-15 09:11:15", "path": "/time", "status": 404, "error": "Not Found", "requestId": "8a3f3980-1" }

It should throw a exception and can be caught by global ExceptionHandler, then the response can be adapted to some customized content.

@bclozel
Copy link
Member

bclozel commented Dec 15, 2023

@BruceAn1978 So this is different from the issue reported here? The project provided by @infoShare has @ExceptionHandler methods contributed by a controller advice. If this is a different problem, please create a new issue with a minimal sample application.

@BruceAn1978
Copy link

@bclozel #38826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants