Moved service, changed componentScan, refactored serverInfoAdvice
This commit is contained in:
parent
aebc35ca3e
commit
4b026ec78c
|
|
@ -11,8 +11,8 @@ import ru.touchin.server.info.services.ServerInfoService
|
|||
|
||||
@RestControllerAdvice
|
||||
class ServerInfoAdvice(
|
||||
private val serverInfoService: ServerInfoService
|
||||
): ResponseBodyAdvice<Any> {
|
||||
private val serverInfoService: List<ServerInfoService>
|
||||
) : ResponseBodyAdvice<Any> {
|
||||
|
||||
override fun supports(
|
||||
returnType: MethodParameter,
|
||||
|
|
@ -29,7 +29,13 @@ class ServerInfoAdvice(
|
|||
request: ServerHttpRequest,
|
||||
response: ServerHttpResponse
|
||||
): Any? {
|
||||
serverInfoService.addHeader(response)
|
||||
for (service in serverInfoService) {
|
||||
response
|
||||
.headers
|
||||
.addAll(
|
||||
service.getHeaders()
|
||||
)
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ import org.springframework.context.annotation.Configuration
|
|||
|
||||
@Suppress("SpringFacetCodeInspection")
|
||||
@Configuration
|
||||
@ComponentScan("ru.touchin.server.info")
|
||||
@ComponentScan("ru.touchin.server.info.advices")
|
||||
@ConfigurationPropertiesScan("ru.touchin.server.info")
|
||||
class ServerInfo
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package ru.touchin.server.info.services
|
||||
|
||||
import org.springframework.http.server.ServerHttpResponse
|
||||
import org.springframework.util.MultiValueMap
|
||||
|
||||
interface ServerInfoService {
|
||||
|
||||
fun addHeader(response: ServerHttpResponse): ServerHttpResponse
|
||||
fun getHeaders(): MultiValueMap<String, String>
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package ru.touchin.server.info.services
|
||||
|
||||
import org.springframework.http.server.ServerHttpResponse
|
||||
import org.springframework.stereotype.Service
|
||||
import ru.touchin.server.info.properties.ServerInfoProperties
|
||||
|
||||
@Service
|
||||
class ServerInfoServiceImpl(
|
||||
private val serverInfoProperties: ServerInfoProperties
|
||||
) : ServerInfoService {
|
||||
|
||||
override fun addHeader(response: ServerHttpResponse): ServerHttpResponse {
|
||||
response
|
||||
.headers
|
||||
.add("X-App-Build-Version", serverInfoProperties.buildVersion)
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package ru.touchin.server.info.services.version
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.util.LinkedMultiValueMap
|
||||
import org.springframework.util.MultiValueMap
|
||||
import ru.touchin.server.info.properties.ServerInfoProperties
|
||||
import ru.touchin.server.info.services.ServerInfoService
|
||||
|
||||
@Service
|
||||
class BuildVersionServiceImpl(
|
||||
private val serverInfoProperties: ServerInfoProperties
|
||||
) : ServerInfoService {
|
||||
|
||||
override fun getHeaders(): MultiValueMap<String, String> {
|
||||
return LinkedMultiValueMap<String, String>()
|
||||
.apply {
|
||||
this.add("X-App-Build-Version", serverInfoProperties.buildVersion)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue