Skip to content

Commit

Permalink
fix: make filters a configuration so they are auto-injected by Spring
Browse files Browse the repository at this point in the history
  • Loading branch information
testersen committed May 27, 2024
1 parent 9e1a0e9 commit 04ad7bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import jakarta.servlet.FilterChain
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import no.telenor.kt.MDCTransaction
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter

@Component
@Order(Ordered.LOWEST_PRECEDENCE)
class MdcAppenderFilter(private val keyRegistry: KeyRegistry) : OncePerRequestFilter() {
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
class MdcAppenderFilter(
private val keyRegistry: KeyRegistry,
// ensure that this filter is loaded after the request context
// filter
@Suppress("UNUSED_PARAMETER") `_`: MdcRequestContextFilter,
) : OncePerRequestFilter() {
override fun doFilterInternal(
request: HttpServletRequest,
response: HttpServletResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import jakarta.servlet.FilterChain
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.beans.factory.BeanFactory
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter

@Component
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
class MdcRequestContextFilter(private val beanFactory: BeanFactory) : OncePerRequestFilter() {
override fun doFilterInternal(
Expand Down

0 comments on commit 04ad7bb

Please sign in to comment.