diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index a83951eb52..de4bc29b0f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java @@ -131,6 +131,8 @@ public class LoggingApplicationListener implements GenericApplicationListener { loggers.add("web", "org.springframework.http"); loggers.add("web", "org.springframework.web"); loggers.add("web", "org.springframework.boot.actuate.endpoint.web"); + loggers.add("web", + "org.springframework.boot.web.servlet.ServletContextInitializerBeans"); loggers.add("sql", "org.springframework.jdbc.core"); loggers.add("sql", "org.hibernate.SQL"); DEFAULT_GROUP_LOGGERS = Collections.unmodifiableMap(loggers); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java index 3926da69fd..dfd2b5a076 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java @@ -41,6 +41,7 @@ import org.springframework.util.StringUtils; * * @param the type of {@link Filter} to register * @author Phillip Webb + * @author Brian Clozel * @since 2.0.1 */ public abstract class AbstractFilterRegistrationBean @@ -245,27 +246,38 @@ public abstract class AbstractFilterRegistrationBean } servletNames.addAll(this.servletNames); if (servletNames.isEmpty() && this.urlPatterns.isEmpty()) { - this.logger.info("Mapping filter: '" + registration.getName() + "' to: " - + Arrays.asList(DEFAULT_URL_MAPPINGS)); registration.addMappingForUrlPatterns(dispatcherTypes, this.matchAfter, DEFAULT_URL_MAPPINGS); } else { if (!servletNames.isEmpty()) { - this.logger.info("Mapping filter: '" + registration.getName() - + "' to servlets: " + servletNames); registration.addMappingForServletNames(dispatcherTypes, this.matchAfter, StringUtils.toStringArray(servletNames)); } if (!this.urlPatterns.isEmpty()) { - this.logger.info("Mapping filter: '" + registration.getName() - + "' to urls: " + this.urlPatterns); registration.addMappingForUrlPatterns(dispatcherTypes, this.matchAfter, StringUtils.toStringArray(this.urlPatterns)); } } } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(getOrDeduceName(this)); + if (this.servletNames.isEmpty() && this.urlPatterns.isEmpty()) { + builder.append(" urls=").append(Arrays.toString(DEFAULT_URL_MAPPINGS)); + } + else { + if (!this.servletNames.isEmpty()) { + builder.append(" servlets=").append(this.servletNames); + } + if (!this.urlPatterns.isEmpty()) { + builder.append(" urls=").append(this.urlPatterns); + } + } + return builder.toString(); + } + /** * Return the {@link Filter} to be registered. * @return the filter diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java index 8f4c4e6554..c136525572 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java @@ -57,6 +57,7 @@ import org.springframework.util.MultiValueMap; * * @author Dave Syer * @author Phillip Webb + * @author Brian Clozel * @since 1.4.0 */ public class ServletContextInitializerBeans @@ -93,6 +94,7 @@ public class ServletContextInitializerBeans .sorted(AnnotationAwareOrderComparator.INSTANCE)) .collect(Collectors.toList()); this.sortedList = Collections.unmodifiableList(sortedInitializers); + logBeansInformation(this.initializers); } private void addServletContextInitializerBeans(ListableBeanFactory beanFactory) { @@ -143,10 +145,10 @@ public class ServletContextInitializerBeans // Mark the underlying source as seen in case it wraps an existing bean this.seen.add(source); } - if (ServletContextInitializerBeans.logger.isDebugEnabled()) { + if (ServletContextInitializerBeans.logger.isTraceEnabled()) { String resourceDescription = getResourceDescription(beanName, beanFactory); int order = getOrder(initializer); - ServletContextInitializerBeans.logger.debug("Added existing " + ServletContextInitializerBeans.logger.trace("Added existing " + type.getSimpleName() + " initializer bean '" + beanName + "'; order=" + order + ", resource=" + resourceDescription); } @@ -200,8 +202,8 @@ public class ServletContextInitializerBeans bean.getValue(), beans.size()); registration.setOrder(order); this.initializers.add(type, registration); - if (ServletContextInitializerBeans.logger.isDebugEnabled()) { - ServletContextInitializerBeans.logger.debug( + if (ServletContextInitializerBeans.logger.isTraceEnabled()) { + ServletContextInitializerBeans.logger.trace( "Created " + type.getSimpleName() + " initializer for bean '" + beanName + "'; order=" + order + ", resource=" + getResourceDescription(beanName, beanFactory)); @@ -245,6 +247,36 @@ public class ServletContextInitializerBeans return beans; } + private void logBeansInformation( + MultiValueMap, ServletContextInitializer> initializers) { + if (ServletContextInitializerBeans.logger.isDebugEnabled()) { + List filterRegistrations = new ArrayList<>(); + filterRegistrations.addAll(initializers + .getOrDefault(FilterRegistrationBean.class, Collections.emptyList())); + filterRegistrations.addAll( + initializers.getOrDefault(Filter.class, Collections.emptyList())); + String filtersInfo = filterRegistrations.stream() + .map(FilterRegistrationBean.class::cast) + .map(FilterRegistrationBean::toString) + .collect(Collectors.joining(", ")); + ServletContextInitializerBeans.logger + .debug("Mapping filters: " + filtersInfo); + + List servletRegistrations = new ArrayList<>(); + servletRegistrations.addAll(initializers.getOrDefault( + ServletRegistrationBean.class, Collections.emptyList())); + servletRegistrations.addAll( + initializers.getOrDefault(Servlet.class, Collections.emptyList())); + String servletsInfo = servletRegistrations.stream() + .map(ServletRegistrationBean.class::cast) + .map((servlet) -> servlet.getServletName() + " " + + servlet.getUrlMappings()) + .collect(Collectors.joining(", ")); + ServletContextInitializerBeans.logger + .debug("Mapping servlets: " + servletsInfo); + } + } + @Override public Iterator iterator() { return this.sortedList.iterator(); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java index b1297f8610..d5456bed19 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java @@ -183,7 +183,6 @@ public class ServletRegistrationBean protected ServletRegistration.Dynamic addRegistration(String description, ServletContext servletContext) { String name = getServletName(); - logger.info("Servlet " + name + " mapped to " + this.urlMappings); return servletContext.addServlet(name, this.servlet); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java index 7cafdd7a4e..a95ec3f26e 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java @@ -570,6 +570,9 @@ public class LoggingApplicationListenerTests { assertTraceEnabled("org.springframework.http", true); assertTraceEnabled("org.springframework.web", true); assertTraceEnabled("org.springframework.boot.actuate.endpoint.web", true); + assertTraceEnabled( + "org.springframework.boot.web.servlet.ServletContextInitializerBeans", + true); } @Test