mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-26 00:32:34 +03:00
main app refactoring
This commit is contained in:
@@ -3,26 +3,12 @@ package com.github.dannecron.demo.config
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.github.dannecron.demo.config.properties.KafkaProperties
|
||||
import com.github.dannecron.demo.config.properties.ValidationProperties
|
||||
import com.github.dannecron.demo.providers.CityRepository
|
||||
import com.github.dannecron.demo.providers.CustomerRepository
|
||||
import com.github.dannecron.demo.providers.ProductRepository
|
||||
import com.github.dannecron.demo.services.database.city.CityService
|
||||
import com.github.dannecron.demo.services.database.city.CityServiceImpl
|
||||
import com.github.dannecron.demo.services.database.customer.CustomerService
|
||||
import com.github.dannecron.demo.services.database.customer.CustomerServiceImpl
|
||||
import com.github.dannecron.demo.services.database.product.ProductService
|
||||
import com.github.dannecron.demo.services.database.product.ProductServiceImpl
|
||||
import com.github.dannecron.demo.services.kafka.Producer
|
||||
import com.github.dannecron.demo.services.validation.SchemaValidator
|
||||
import com.github.dannecron.demo.services.validation.SchemaValidatorImp
|
||||
import io.ktor.client.engine.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
import com.github.dannecron.demo.core.config.properties.ValidationProperties
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.micrometer.observation.ObservationRegistry
|
||||
import io.micrometer.observation.aop.ObservedAspect
|
||||
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
@@ -31,10 +17,8 @@ import com.github.dannecron.demo.services.neko.Client as NekoClient
|
||||
import com.github.dannecron.demo.services.neko.ClientImpl as NekoClientImpl
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(KafkaProperties::class, ValidationProperties::class)
|
||||
class AppConfig(
|
||||
@Autowired private val kafkaProperties: KafkaProperties,
|
||||
) {
|
||||
@EnableConfigurationProperties(ValidationProperties::class)
|
||||
class AppConfig {
|
||||
@Bean
|
||||
fun objectMapper(): ObjectMapper = ObjectMapper().apply {
|
||||
registerModules(JavaTimeModule())
|
||||
@@ -42,43 +26,20 @@ class AppConfig(
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun productService(
|
||||
@Autowired productRepository: ProductRepository,
|
||||
@Autowired producer: Producer,
|
||||
): ProductService = ProductServiceImpl(
|
||||
kafkaProperties.producer.product.defaultSyncTopic,
|
||||
productRepository,
|
||||
producer,
|
||||
)
|
||||
fun otlpHttpSpanExporter(@Value("\${tracing.url}") url: String): OtlpHttpSpanExporter =
|
||||
OtlpHttpSpanExporter.builder()
|
||||
.setEndpoint(url)
|
||||
.build()
|
||||
|
||||
@Bean
|
||||
fun cityService(@Autowired cityRepository: CityRepository): CityService = CityServiceImpl(cityRepository)
|
||||
|
||||
@Bean
|
||||
fun customerService(
|
||||
@Autowired customerRepository: CustomerRepository,
|
||||
@Autowired cityRepository: CityRepository,
|
||||
): CustomerService = CustomerServiceImpl(customerRepository, cityRepository)
|
||||
|
||||
@Bean
|
||||
fun schemaValidator(
|
||||
@Autowired validationProperties: ValidationProperties,
|
||||
): SchemaValidator = SchemaValidatorImp(validationProperties.schema)
|
||||
|
||||
@Bean
|
||||
fun otlpHttpSpanExporter(@Value("\${tracing.url}") url: String) = OtlpHttpSpanExporter.builder()
|
||||
.setEndpoint(url)
|
||||
.build()
|
||||
|
||||
@Bean
|
||||
fun observedAspect(@Autowired observationRegistry: ObservationRegistry) = ObservedAspect(observationRegistry)
|
||||
fun observedAspect(observationRegistry: ObservationRegistry) = ObservedAspect(observationRegistry)
|
||||
|
||||
@Bean
|
||||
fun httpClientEngine(): HttpClientEngine = CIO.create()
|
||||
|
||||
@Bean
|
||||
fun nekoClient(
|
||||
@Autowired httpClientEngine: HttpClientEngine,
|
||||
httpClientEngine: HttpClientEngine,
|
||||
@Value("\${neko.baseUrl}") baseUrl: String,
|
||||
): NekoClient = NekoClientImpl(
|
||||
engine = httpClientEngine,
|
||||
|
||||
Reference in New Issue
Block a user