4

I am using the spring-boot-starter-web bundle to build a spring-batch-admin based webapp.

@Configuration
@EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class, DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class })
@Import(MainConfiguration.class)
@EnableTransactionManagement
public class BatchAdmin extends SpringBootServletInitializer {

  public static void main(String[] args) {
    SpringApplication.run(BatchAdmin.class, args);
  }
  // ...
}      

@Configuration
@ComponentScan("com.company.package*")
@Import({ ServletConfiguration.class, WebappConfiguration.class })
public class MainConfiguration {}

@Configuration
@ImportResource("classpath:/org/springframework/batch/admin/web/resources/servlet-config.xml")
public class ServletConfiguration {}

@Configuration
@ImportResource({ "classpath:/org/springframework/batch/admin/web/resources/webapp-config.xml","classpath:persistence-context.xml" })
public class WebappConfiguration {}

How can I add this filter to the servlet context using the java configuration style?

<filter-mapping>
    <filter-name>hiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
achingfingers
  • 1,827
  • 5
  • 24
  • 48

1 Answers1

4

Sometimes (but not often) it's faster to consult the documentation than asking the SO community.

According to the official spring-boot documentation, I had to add the following bean definition to the BatchAdmin class.

@Bean
public Filter hiddenHttpMethodFilter() {
   HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter();
   return filter;
}
achingfingers
  • 1,827
  • 5
  • 24
  • 48