Last active
May 9, 2018 09:57
-
-
Save chenminhua/c5da2e81dcc63a88018fbdb52db6d7e6 to your computer and use it in GitHub Desktop.
Spring Auto Configure
This file contains 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
@Configuration | |
public class PrometheusAutoConfigure { | |
@Bean | |
SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> publicMetrics) { | |
SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(publicMetrics); | |
springBootMetricsCollector.register(); | |
return springBootMetricsCollector; | |
} | |
@Bean | |
ServletRegistrationBean servletRegistrationBean() { | |
DefaultExports.initialize(); | |
return new ServletRegistrationBean(new MetricsServlet(), "/prometheus"); | |
} | |
} |
This file contains 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
import io.sentry.spring.SentryExceptionResolver | |
import org.springframework.beans.factory.annotation.Value | |
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | |
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | |
import org.springframework.boot.context.properties.ConfigurationProperties | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
@Configuration | |
@ConfigurationProperties("sentry") | |
@ConditionalOnProperty("sentry.dsn") | |
open class SentryAutoConfigure() { | |
@Value("\${sentry.dsn}") | |
lateinit var value: String | |
@Bean @ConditionalOnMissingBean | |
open fun sentryExceptionResolver(): SentryExceptionResolver { | |
io.sentry.Sentry.init(value) | |
return io.sentry.spring.SentryExceptionResolver() | |
} | |
@Bean @ConditionalOnMissingBean | |
open fun sentryServletContextInitializer() = io.sentry.spring.SentryServletContextInitializer() | |
} |
This file contains 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
@Configuration | |
@EnableSwagger2 | |
@EnableConfigurationProperties(BarrenProperties::class) | |
open class SwaggerAutoConfigure { | |
@Autowired | |
lateinit var barrenProperties: BarrenProperties | |
@Bean | |
open fun api(): Docket { | |
return Docket(DocumentationType.SWAGGER_2) | |
.groupName("service") | |
.apiInfo(info()) | |
.select() | |
.apis(RequestHandlerSelectors.any()) | |
.paths(PathSelectors.regex("/[vV][0-9]+/.*")) | |
.build() | |
} | |
@Bean | |
open fun all(): Docket { | |
return Docket(DocumentationType.SWAGGER_2) | |
.groupName("all") | |
.select() | |
.apis(RequestHandlerSelectors.any()) | |
.paths(PathSelectors.any()) | |
.build() | |
} | |
open fun info(): ApiInfo { | |
return ApiInfoBuilder() | |
.title(barrenProperties.appName) | |
.version(barrenProperties.version) | |
.build() | |
} | |
} |
This file contains 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
@Configuration | |
@ConditionalOnClass(UndertowEmbeddedServletContainerFactory::class) | |
open class UndertowAutoConfiguration { | |
@Bean @ConditionalOnMissingBean | |
open fun embeddedServletContainerFactory(): UndertowEmbeddedServletContainerFactory { | |
val factory = UndertowEmbeddedServletContainerFactory() | |
factory.addBuilderCustomizers( | |
UndertowBuilderCustomizer { | |
it.setServerOption(UndertowOptions.ENABLE_HTTP2, true) | |
} | |
) | |
return factory | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment