All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.byu.hbll.spring.common.TrailingSlashAutoConfiguration Maven / Gradle / Ivy

The newest version!
package edu.byu.hbll.spring.common;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.UrlHandlerFilter;

/**
 * With Spring Boot 3.0, paths with trailing slashes were no longer treated the same as paths
 * without trailing slashes. The Spring team later added built-in support to effectively rollback
 * the change. This auto configuration configures the application to treat both variations as the
 * same. This can be disabled by setting the property denoted in the ConditionalOnProperty
 * annotation to false.
 */
@ConditionalOnClass(UrlHandlerFilter.class)
@ConditionalOnMissingBean(UrlHandlerFilter.class)
@ConditionalOnProperty(name = "byuhbll.spring-common.trailing-slash.enabled", matchIfMissing = true)
public class TrailingSlashAutoConfiguration {

  /**
   * Registers a {@link UrlHandlerFilter} that treats trailing slashes the same as no trailing
   * slashes.
   *
   * @return a {@link UrlHandlerFilter} that treats trailing slashes the same as no trailing slashes
   */
  @Bean
  public UrlHandlerFilter urlHandlerFilter() {
    return UrlHandlerFilter.trailingSlashHandler("/**").wrapRequest().build();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy