Last active
October 3, 2016 17:46
-
-
Save jkschneider/95d0a54e7382c1d96f016ca968d63e77 to your computer and use it in GitHub Desktop.
InterceptorConfig Kotlin example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sazzad | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.boot.autoconfigure.SpringBootApplication | |
import org.springframework.boot.builder.SpringApplicationBuilder | |
import org.springframework.context.annotation.ComponentScan | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.stereotype.Component | |
import org.springframework.web.servlet.HandlerInterceptor | |
import org.springframework.web.servlet.ModelAndView | |
import org.springframework.web.servlet.config.annotation.EnableWebMvc | |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter | |
import javax.servlet.http.HttpServletRequest | |
import javax.servlet.http.HttpServletResponse | |
@SpringBootApplication | |
@Configuration | |
@EnableWebMvc | |
@ComponentScan | |
open class WebConfig() : WebMvcConfigurerAdapter() { | |
@Autowired | |
lateinit var interceptorConfig: InterceptorConfig | |
override fun addInterceptors(registry: InterceptorRegistry) { | |
registry.addInterceptor(interceptorConfig) | |
} | |
} | |
@Component | |
open class InterceptorConfig: HandlerInterceptor { | |
override fun preHandle(request: HttpServletRequest?, response: HttpServletResponse?, handler: Any?): Boolean { | |
return true | |
} | |
override fun postHandle(request: HttpServletRequest?, response: HttpServletResponse?, handler: Any?, modelAndView: ModelAndView?) { | |
} | |
override fun afterCompletion(request: HttpServletRequest?, response: HttpServletResponse?, handler: Any?, ex: Exception?) { | |
} | |
} | |
fun main(args: Array<String>) { | |
SpringApplicationBuilder(WebConfig::class.java).run(*args) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment