<big id="yeiyz"><ruby id="yeiyz"></ruby></big>
    <track id="yeiyz"></track>
    <track id="yeiyz"></track>
    <p id="yeiyz"><del id="yeiyz"></del></p><td id="yeiyz"><option id="yeiyz"></option></td>
    1. <p id="yeiyz"></p>

      <td id="yeiyz"></td>

      bean注入失敗

      王靜0716 發布于 2018/10/15 17:24
      閱讀 76
      收藏 0

      吳曉波激蕩2020特別演講,讀懂2020的中國數字經濟趨勢,限時觀看!>>>

      package com.example.serviceribbon
      
      import org.slf4j.LoggerFactory
      import org.springframework.boot.SpringApplication
      import org.springframework.boot.autoconfigure.SpringBootApplication
      import org.springframework.cloud.client.discovery.EnableDiscoveryClient
      import org.springframework.cloud.client.loadbalancer.LoadBalanced
      import org.springframework.cloud.netflix.eureka.EnableEurekaClient
      import org.springframework.cloud.netflix.hystrix.EnableHystrix
      import org.springframework.context.annotation.Bean
      import org.springframework.web.client.RestTemplate
      
      @SpringBootApplication
      @EnableEurekaClient
      @EnableDiscoveryClient
      @EnableHystrix
      open class ServiceRibbonApplication {
      
          private val logger = LoggerFactory.getLogger(ServiceRibbonApplication::class.java)
      
          @Bean
          @LoadBalanced
          open fun restTemplate(): RestTemplate// = RestTemplate()
          {
              logger.debug("-----------------")
              return RestTemplate()
          }
      
      }
      
      fun main(args: Array<String>) {
          SpringApplication.run(ServiceRibbonApplication::class.java, *args)
      }
      package com.example.serviceribbon.service
      
      import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand
      import org.springframework.beans.factory.annotation.Autowired
      import org.springframework.stereotype.Service
      import org.springframework.web.client.RestTemplate
      import org.springframework.web.client.getForObject
      
      
      @Service
      open class HelloService {
      
          @Autowired
          private lateinit var restTemplate: RestTemplate
      
      
          @HystrixCommand(fallbackMethod = "hiError")
          fun hiService(name: String): String {
              return restTemplate.getForObject("http://EUREKA-CLIENT/hi?name=$name", String::class) ?: "sb"
          }
      
          fun hiError(name: String): String {
              return "hi,$name,error"
          }
      
      
      }

      啟動不報錯,但是也沒有打印

      -----------------

      調用報錯

      kotlin.UninitializedPropertyAccessException: lateinit property restTemplate has not been initialized

       

      去掉

      @HystrixCommand(fallbackMethod = "hiError")

      就可以。

      why?

      加載中
      返回頂部
      頂部
      聚看影院