Skip to content

Commit c623303

Browse files
committed
Add Logging
Now if the ServletRegistration API available message is shown, it will also be accompanied with a startup warning in the logs. Closes gh-14221
1 parent a98baa7 commit c623303

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import javax.servlet.ServletRegistration;
3131
import javax.servlet.http.HttpServletRequest;
3232

33+
import org.apache.commons.logging.Log;
34+
import org.apache.commons.logging.LogFactory;
35+
3336
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3437
import org.springframework.context.ApplicationContext;
3538
import org.springframework.http.HttpMethod;
@@ -75,6 +78,8 @@ public abstract class AbstractRequestMatcherRegistry<C> {
7578
AbstractRequestMatcherRegistry.class.getClassLoader());
7679
}
7780

81+
private final Log logger = LogFactory.getLog(getClass());
82+
7883
protected final void setApplicationContext(ApplicationContext context) {
7984
this.context = context;
8085
}
@@ -326,6 +331,10 @@ public C requestMatchers(HttpMethod method, String... patterns) {
326331
matchers.add(resolve(ant, mvc, servletContext));
327332
}
328333
else {
334+
this.logger
335+
.warn("The ServletRegistration API was not available at startup time. This may be due to a misconfiguration; "
336+
+ "if you are using AbstractSecurityWebApplicationInitializer, please double-check the recommendations outlined in "
337+
+ "https://docs.spring.io/spring-security/reference/servlet/configuration/java.html#abstractsecuritywebapplicationinitializer-with-spring-mvc");
329338
matchers.add(new DeferredRequestMatcher((request) -> resolve(ant, mvc, request.getServletContext()),
330339
mvc, ant));
331340
}

0 commit comments

Comments
 (0)