91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Spring中有哪些bean

發布時間:2021-12-16 09:41:18 來源:億速云 閱讀:346 作者:iii 欄目:編程語言

這篇文章主要講解了“Spring中有哪些bean”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Spring中有哪些bean”吧!

  Spring中有兩種bean, 用的最多的是 annotationBean,但是對于一些客制化的需求,可以使用 factoryBean, 它提供了三個接口

  @Nullable

  T getObject() throws Exception;

  @Nullable

  Class getObjectType();

  default boolean isSingleton() {

  return true;

  }

  定義

  @Component

  class AutoMoneyHouseExtApiProxyCreator : BeanFactoryPostProcessor {

  private val logger: Logger = LogManager.getLogger()

  override fun postProcessBeanFactory(beanFactory: ConfigurableListableBeanFactory) {

  ServiceProvider::class.java.declaredFields.filter {

  it.isEnumConstant && it.isAnnotationPresent(Rail::class.java)

  }.forEach {

  val railId = it.getAnnotation(Rail::class.java).id

  val provider = it.get(null) as ServiceProvider

  createApiProxy(railId, provider, beanFactory as BeanDefinitionRegistry)

  }

  }

  private fun createApiProxy(railId: String, provider: ServiceProvider,

  registry: BeanDefinitionRegistry) {

  logger.info("auto-generate api proxy for: {}", provider)

  val mhId = provider.providerName

  // Payment API

  if (provider.services.contains(Service.PAYMENT)) {

  val railsDisbBeanDef = BeanDefinitionBuilder.rootBeanDefinition(DisbursementRpcServiceProxyFactoryBean::class.java)

  .addConstructorArgValue(railId)

  .addConstructorArgValue(mhId)

  .beanDefinition

  val railsDisbBeanName = "rails-disb-${provider.name}"

  registry.registerBeanDefinition(railsDisbBeanName, railsDisbBeanDef)

  val paymentBeanDef = BeanDefinitionBuilder.rootBeanDefinition(DisbursementCPAPIImpl::class.java)

  .addConstructorArgValue(mhId)

  .addConstructorArgReference(railsDisbBeanName)

  .addConstructorArgValue(provider)

  .beanDefinition

  registry.registerBeanDefinition(Service.PAYMENT.name + "-" + provider.name, paymentBeanDef)

  }

  // Balance API

  val railsBalBeanDef = BeanDefinitionBuilder.rootBeanDefinition(AccountBalanceRpcServiceProxyFactoryBean::class.java)

  .addConstructorArgValue(railId)

  .addConstructorArgValue(mhId)

  .beanDefinition

  val railsBalBeanName = "rails-bal-${provider.name}"

  registry.registerBeanDefinition(railsBalBeanName, railsBalBeanDef)

  val balanceBeanDef = BeanDefinitionBuilder.rootBeanDefinition(BalanceAPIServiceAdapter::class.java)

  .addConstructorArgValue(mhId)

  .addConstructorArgReference(railsBalBeanName)

  .beanDefinition

  registry.registerBeanDefinition("BALANCE-" + provider.name, balanceBeanDef)

  }

  }

  class DisbursementRpcServiceProxyFactoryBean(private val railId: String, private val mhId: MoneyHouseID)

  : FactoryBean {

  @Autowired

  lateinit var restTemplate: RestTemplate

  @Value("\${application.railsGateway.url}")

  var railsGatewayUrl: String = ""

  override fun getObject(): DisbursementRpcService {

  val client = JsonRpcRestClient(URL(URL(railsGatewayUrl), railId + DisbursementRpcService.SERVICE_PATH),

  Codecs.NO_NULL_FIELD_ORDERED_MAPPER, restTemplate,

  mapOf("mhId" to mhId))

  return ProxyUtil.createClientProxy(javaClass.classLoader, DisbursementRpcService::class.java, client)

  }

  override fun getObjectType() = DisbursementRpcService::class.java

  }

  class AccountBalanceRpcServiceProxyFactoryBean(private val railId: String, private val mhId: MoneyHouseID)

  : FactoryBean {

  @Autowired無錫人流醫院哪家好 http://www.ytsg029.com/

  lateinit var restTemplate: RestTemplate

  @Value("\${application.railsGateway.url}")

  var railsGatewayUrl: String = ""

  override fun getObject(): AccountBalanceRpcService {

  val client = JsonRpcRestClient(URL(URL(railsGatewayUrl), railId + AccountBalanceRpcService.SERVICE_PATH),

  Codecs.NO_NULL_FIELD_ORDERED_MAPPER, restTemplate,

  mapOf("mhId" to mhId))

  return ProxyUtil.createClientProxy(javaClass.classLoader, AccountBalanceRpcService::class.java, client)

  }

  override fun getObjectType() = AccountBalanceRpcService::class.java

  }

  使用

  @Target(AnnotationTarget.FIELD)

  annotation class Rail(val id: String)

  enum class ServiceProvider constructor(val providerName: String, vararg list: Service) {

  @Rail("ttt") TTTT(MHHIDs.TTTT, Service.CONVERSION, Service.PAYMENT)

  val services: Array = arrayOf(*list)

  }

  精髓

  生成beanDef:

  BeanDefinitionBuilder.rootBeanDefinition(DisbursementRpcServiceProxyFactoryBean::class.java)

  .addConstructorArgValue(railId)

  .addConstructorArgValue(mhId)

  .beanDefinition

  注冊bean

  registry.registerBeanDefinition(railsDisbBeanName, railsDisbBeanDef)

  其中 registry:

  void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;

  registry = beanFactory

感謝各位的閱讀,以上就是“Spring中有哪些bean”的內容了,經過本文的學習后,相信大家對Spring中有哪些bean這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

永济市| 手游| 广宁县| 彰武县| 五华县| 比如县| 巩留县| 巫山县| 叙永县| 新安县| 原阳县| 内丘县| 瑞丽市| 醴陵市| 静海县| 西昌市| 闽清县| 永年县| 自治县| 苍山县| 博客| 祁东县| 前郭尔| 武城县| 镇巴县| 土默特左旗| 鱼台县| 随州市| 临邑县| 竹溪县| 大足县| 中方县| 莒南县| 普陀区| 曲沃县| 射阳县| 嫩江县| 通河县| 嘉义市| 陕西省| 登封市|