import net.javacrumbs.shedlock.core.LockProvider
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider
import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.data.redis.RedisProperties
import org.springframework.boot.builder.SpringApplicationBuilder
+import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.web.servlet.ServletComponentScan
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
import org.springframework.cache.annotation.EnableCaching
import org.springframework.http.client.ClientHttpRequestFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory
import org.springframework.scheduling.annotation.EnableScheduling
+import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate
+import java.net.InetSocketAddress
+import java.net.Proxy
@Configuration
@Configuration
class RestTemplateConfig {
+ @Component
+ @ConfigurationProperties("resttemplate.proxy")
+ class RestTemplateProxyConfig {
+ @Value("\${type:}")
+ lateinit var type: String
+ @Value("\${host:}")
+ lateinit var host: String
+ @Value("\${port:0}")
+ var port: Int = 0
+ }
+
@Bean
- fun simpleClientHttpRequestFactory(): SimpleClientHttpRequestFactory {
+ fun simpleClientHttpRequestFactory(proxyConfig: RestTemplateProxyConfig): SimpleClientHttpRequestFactory {
val factory = SimpleClientHttpRequestFactory()
factory.setConnectTimeout(15000)
factory.setReadTimeout(5000)
+ if (proxyConfig.type.isNotEmpty()) {
+ val proxyType = when (proxyConfig.type) {
+ "http" -> Proxy.Type.HTTP
+ "socks5" -> Proxy.Type.SOCKS
+ else -> Proxy.Type.DIRECT
+ }
+ factory.setProxy(Proxy(proxyType, InetSocketAddress(proxyConfig.host, proxyConfig.port)))
+ }
return factory
}