Skip to content

Avoid reinitializing dispatcher servlet on refresh#8974

Open
frhack wants to merge 1 commit into
apereo:masterfrom
frhack:fix/syncope-1758-dispatcher-servlet-refresh-master
Open

Avoid reinitializing dispatcher servlet on refresh#8974
frhack wants to merge 1 commit into
apereo:masterfrom
frhack:fix/syncope-1758-dispatcher-servlet-refresh-master

Conversation

@frhack
Copy link
Copy Markdown

@frhack frhack commented May 17, 2026

Problem

The CAS configuration refresh listener eagerly resolves application context beans after refresh, but it also special-cases the dispatcherServlet bean and manually calls DispatcherServlet.init().

That call can run outside the servlet container lifecycle, where no ServletConfig is available. This may surface as a NullPointerException during refresh.

This was observed downstream in Apache Syncope WA:
https://issues.apache.org/jira/browse/SYNCOPE-1758

Root Cause

DefaultCasConfigurationEventListener#initializeBeansEagerly() currently:

  • checks for dispatcherServlet
  • retrieves DispatcherServlet.class
  • sets the application context
  • calls servlet.init()

The refresh listener should eagerly resolve beans as needed, but it should not manually initialize Spring MVC's DispatcherServlet. The servlet container/Spring Boot web lifecycle should own that initialization.

Changes

This removes the special-case reinitialization of Spring's DispatcherServlet from the CAS configuration refresh listener.

The listener still eagerly resolves all beans after refresh, but it no longer calls DispatcherServlet.init() manually.

References

Checklist

  • Brief description of changes applied
  • Test cases for modified changes
  • Pull request targets master
  • Possible limitations or side effects documented
  • Related issue referenced

Tests

  • JAVA_HOME=/tmp/jdk25 ../../gradlew --no-daemon testCasConfiguration --tests org.apereo.cas.support.events.listener.CasConfigurationEventListenerTests

The CAS configuration refresh listener eagerly resolves beans after refresh, but it should not manually initialize the DispatcherServlet. Calling DispatcherServlet.init() outside the servlet container can fail because no ServletConfig is available.

This surfaced downstream in Apache Syncope WA as SYNCOPE-1758: https://issues.apache.org/jira/browse/SYNCOPE-1758
@welcome
Copy link
Copy Markdown

welcome Bot commented May 17, 2026

Thank you so much for opening your first pull request here!

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 this pull request may close these issues.

2 participants