1

I have a HandlerInterceptor implemented with jakarta libraries:

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;



@ControllerAdvice
public class RequestGETInterceptor implements HandlerInterceptor {

    /** The log. */
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private Tracer       tracer;

    public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,
            final Object handler) {

        if (DispatcherType.REQUEST.name().equals(request.getDispatcherType().name())
                && request.getMethod().equals(HttpMethod.GET.name())) {
            Collections.list(request.getHeaderNames()).stream().collect(Collectors.toMap(h -> h, request::getHeader));
            request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
            if (handler instanceof HandlerMethod) {
                ((HandlerMethod) handler).getMethod().getName();
            }

            final Span span = this.tracer.currentSpan();
            this.log.info("{} Request {}", request.getMethod(), span.context().spanId());

            // log.info("headers: {} {} request: {}", headers, StructuredArguments.keyValue("method", method),
            // StructuredArguments.keyValue("request", parametersInput));
        }

        return true;
    }

And I register this Interceptor in configuration of my app with SpringBoot:

@Configuration
public class WebConfigInterceptors implements WebMvcConfigurer {

    @Autowired
    private RequestGETInterceptor getInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getInterceptor);
    }

}

The problem, I think, is that my project uses javax libraries and my library (where the interceptor stay in) use jakarta libraris and doesn't intercept the requests. Any idea for solve this?

Thanks!!!

witilongi
  • 71
  • 3
  • Can you please include some additional information regarding versions, Spring etc. Also I believe you would need to ensure every library is up to date with jakarta dependencies and not using any old javax ones. – zoobiE- Mar 30 '23 at 13:04
  • Yes of course!! Spring-web in library is version 6.0.5 and spring-web in war project is 5.3.23. I hope this help you! – witilongi Mar 30 '23 at 13:48
  • There is your problem, you can't mix those unfortunately since one is using javax and other Jakarta dependencies. – zoobiE- Mar 31 '23 at 09:16

1 Answers1

2

You cannot mix Spring MVC 5.3.x and 6.0.x in the same application. As you have seen, the former requires javax.servlet while the latter requires jakarta.servlet. You will either have to upgrade your war project to use Spring Framework 6.0.x or downgrade you library to use Spring Framework 5.3.x. The servlet container to which you are deploying the war file will determine which is the better approach. If it supports Servlet 5.0 or later, you should upgrade to Spring Framework 6.0. If it only supports Servlet 4.0, you should downgrade to Spring Framework 5.3.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242