I cannot include the actual code here, but I will create an approximation of the problem.
Spring Boot 2.5.6
I have the following functionality, in which I have a request-scoped bean, to hold information captured by the filter.
@Component
@RequestScope
public class HolderBean {
private Object held = null;
HolderBean() {}
void setObject(Object o) {
held = o;
}
public Optional<Object> getObject() {
return Optional.ofNullable(held);
}
}
@RequiredArgsConstructor
public class HolderFilter extends OncePerRequestFilter {
private final HolderBean holder;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
holder.setObject(123);
filterChain.doFilter(request, response);
}
}
@Component
public class HolderFilterRegistration extends FilterRegistrationBean<HolderFilter> {
public HolderFilterRegistration(HolderBean holder) {
this.setFilter(new HolderFilter(holder));
}
}
This works perfect. No issues at all. But, when I include the following dependency into Gradle:
developmentOnly("org.springframework.boot:spring-boot-devtools")
It stops working, and the request-scoped holder bean is always empty. Doing some logging, I am able to see that the filter executes, and that the holder bean is updated. It is just that by the time the controller method is executed, the holder no longer has a value.
So, the problem seems to be related to request-scoped beans getting lost.
Comment From: philwebb
I cannot include the actual code here, but I will create an approximation of the problem.
Are you able to create a sample application of your approximation and either share it as a GitHub project or attach it as a zip? It will be easier for us to debug if we have a project that we can run.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.