1
我有使用springboot和scala构建的简单webapp。我可以在我的应用程序中创建一个简单的休息API。我现在试图添加一个过滤器来支持etags。但是,我没有这样做。这是我的主应用程序的外观。我在设置过滤器时错过了什么吗?筛选到scala springboot应用程序
object SampleApplication {
def main(args: Array[String]) {
println("SA:>>>>hello inside main");
SpringApplication.run(classOf[Launcher]);
}
}
@Configuration
@EnableAutoConfiguration
@ComponentScan
class Launcher extends SpringBootServletInitializer {
println("SA:>>>>>>inside Launcher beg")
override def onStartup(servletContext: ServletContext): Unit = {
println("SA:>>>>inside Launcher onStartup")
servletContext.addFilter("etagFilter","org.springframework.web.filter.ShallowEtagHeaderFilter").addMappingForServletNames(null,false,"/*");
//super.onStartup(servletContext)
}
override def configure(app: SpringApplicationBuilder): SpringApplicationBuilder = {
println("SA:>>>>> inside Launcher")
app.sources(classOf[Launcher])
//super.configure(app)
}
}
你不应该重写'onStartup'使用'main'启动应用程序的'SpringBootServletInitializer'甚至不使用时,打破了'SpringBootServletInitializer',旁边。只需将过滤器添加为配置,Spring Boot将为您注册。这也是[这里]解释(http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-embedded-container- servlet和过滤器)。 – 2014-09-30 09:14:32
@ M.Deinum - 感谢您的回复。发表答案。 – plspl 2014-10-01 06:03:07