feat : 게시글 조회 FeignClient 컴포넌트 추가
This commit is contained in:
@@ -2,7 +2,9 @@ package com.banjjoknim.springcloudopenfeign
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients
|
||||
|
||||
@EnableFeignClients
|
||||
@SpringBootApplication
|
||||
class SpringCloudOpenFeignApplication
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.banjjoknim.springcloudopenfeign.configuration
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
|
||||
|
||||
@Configuration
|
||||
class FeignConfiguration : Jackson2ObjectMapperBuilderCustomizer {
|
||||
override fun customize(jacksonObjectMapperBuilder: Jackson2ObjectMapperBuilder) {
|
||||
jacksonObjectMapperBuilder
|
||||
.featuresToEnable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)
|
||||
.featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.banjjoknim.springcloudopenfeign.domain
|
||||
|
||||
data class Post(
|
||||
val userId: Long,
|
||||
val id: Long,
|
||||
val title: String,
|
||||
val completed: Boolean
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.banjjoknim.springcloudopenfeign.domain
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
|
||||
@FeignClient(value = "postClient", url = "https://jsonplaceholder.typicode.com/")
|
||||
interface PostClient {
|
||||
|
||||
@GetMapping("/posts")
|
||||
fun findPosts(): List<Post>
|
||||
|
||||
@GetMapping("/posts/{postId}")
|
||||
fun findPost(@PathVariable postId: Long): Post
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.banjjoknim.springcloudopenfeign.domain
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class PostController(
|
||||
private val postClient: PostClient
|
||||
) {
|
||||
|
||||
@GetMapping("/posts")
|
||||
fun posts(): List<Post> {
|
||||
return postClient.findPosts()
|
||||
}
|
||||
|
||||
@GetMapping("/posts/{postId}")
|
||||
fun post(@PathVariable postId: Long): Post {
|
||||
return postClient.findPost(postId)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user