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

Auto-configure not working when using @SpringBootApplication #777

Closed
echoesbr opened this issue Apr 19, 2022 · 2 comments
Closed

Auto-configure not working when using @SpringBootApplication #777

echoesbr opened this issue Apr 19, 2022 · 2 comments
Labels

Comments

@echoesbr
Copy link

echoesbr commented Apr 19, 2022

Description

The library is not initialised when using the annotation @SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)

Expected Behavior

The expected behaviour should be the default error response from the library.

Actual Behavior

The default Spring boot response is returned (empty).

Steps to Reproduce

  1. Added library
    <dependency> <groupId>org.zalando</groupId> <artifactId>problem-spring-web-starter</artifactId> <version>0.27.0</version> </dependency>

  2. Configure Spring boot
    web: resources: add-mappings: false mvc: throw-exception-if-no-handler-found: true

  3. Used annotation
    @SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)

  4. Alternatively tried with following without success
    @EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class}) @Configuration @ComponentScan(basePackages = "com.foo.bar") @SpringBootConfiguration

Your Environment

  • Version used: 0.27.0
  • Spring Boot version: 2.6.6
@echoesbr echoesbr added the Bug label Apr 19, 2022
@echoesbr
Copy link
Author

Realised that my application already had a @ControllerAdvice class, so the one from the library was not being instantiated. Maybe worth mentioning in the docs.

@rafaelpontezup
Copy link

rafaelpontezup commented Aug 17, 2022

I had the same issue 😖

I have to be honest, I'm still not sure if I must configure @EnableAutoConfiguration when using the problem-spring-web-starter on pom.xml.

When I add the following config:

@EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class)

And there's any @ControllerAdvice in the application, like this one:

@ControllerAdvice
public class ResponseStatusExceptionHandler implements ResponseStatusAdviceTrait {

    @Override
    public ProblemBuilder prepare(Throwable throwable, StatusType status, URI type) {
        ResponseStatusException exception = (ResponseStatusException) throwable;
        return Problem.builder()
                .withTitle(status.getReasonPhrase())
                .withStatus(status)
                .withDetail(exception.getReason())
                ;
    }
}

Everything stopped working.

But if I disable the ResponseStatusExceptionHandler (like commenting the annotation out) everything works again!

Could you guys give us any help?

echoesbr added a commit to echoesbr/problem-spring-web that referenced this issue Jan 28, 2023
This PR introduces a section in the Spring MVC installation README.md regarding the situation when there is an existing ControllerAdvice. Additionally I've updated the application.properties config path which was outdated.

This PR refers to an issue I've opened some time back - zalando#777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants