国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - 關(guān)于SpringBoot獲取IOC容器中注入的Bean(推薦)

關(guān)于SpringBoot獲取IOC容器中注入的Bean(推薦)

2021-04-29 10:56noodles1994 Java教程

本文通過實(shí)例代碼給大家詳解了springboot獲取ioc容器中注入的bean問題,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧

一: 注入一個testutils類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.shop.sell.utils;
import com.shop.sell.dto.cartdto;
import org.springframework.context.annotation.bean;
import org.springframework.context.annotation.configuration;
@configuration
public class testutils {
  @bean(name="testdemo")
  public cartdto said() {
    cartdto cartdto = new cartdto();
    cartdto.setproductid(789);
    cartdto.setproductquantity(10);
    return cartdto;
  }
}

    二: 創(chuàng)建一個獲取bean的公共類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.shop.sell.utils;
import org.springframework.beans.beansexception;
import org.springframework.context.applicationcontext;
import org.springframework.context.applicationcontextaware;
import org.springframework.stereotype.component;
@component
public class springutil implements applicationcontextaware{
  private static applicationcontext applicationcontext;
  @override
  public void setapplicationcontext(applicationcontext applicationcontext) throws beansexception {
    if(springutil.applicationcontext == null) {
      springutil.applicationcontext = applicationcontext;
    }
  }
  public static applicationcontext getapplicationcontext() {
    return applicationcontext;
  }
  public static object getbean(string name){
    return getapplicationcontext().getbean(name);
  }
  public static <t> t getbean(class<t> clazz){
    return getapplicationcontext().getbean(clazz);
  }
  public static <t> t getbean(string name,class<t> clazz){
    return getapplicationcontext().getbean(name, clazz);
  }
}

三: 在控制器中獲取bean測試結(jié)果

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.shop.sell.controller;
import com.shop.sell.utils.resultvoutil;
import com.shop.sell.utils.springutil;
import com.shop.sell.vo.productinfovo;
import com.shop.sell.vo.productvo;
import com.shop.sell.vo.resultvo;
import com.shop.sell.dataobject.productcategory;
import com.shop.sell.dataobject.productinfo;
import com.shop.sell.dto.cartdto;
import com.shop.sell.from.orderform;
import com.shop.sell.service.categoryservice;
import com.shop.sell.service.productservice;
import org.springframework.beans.beanutils;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.context.applicationcontext;
import org.springframework.web.bind.annotation.getmapping;
import org.springframework.web.bind.annotation.requestmapping;
import org.springframework.web.bind.annotation.restcontroller;
import java.util.arraylist;
import java.util.arrays;
import java.util.list;
/**
 * 買家商品
 */
@restcontroller
@requestmapping("/buyer/product")
public class buyerproductcontroller {
  private static applicationcontext applicationcontext;
  @autowired
  private productservice productservice;
  @autowired
  private categoryservice categoryservice;
  @getmapping(value = "/list")
  public cartdto list(){
    cartdto cartdto = (cartdto) springutil.getbean("testdemo");
    return cartdto;
  }
}

四: 使用postman測試結(jié)果

關(guān)于SpringBoot獲取IOC容器中注入的Bean(推薦)

總結(jié)

以上所述是小編給大家介紹的關(guān)于springboot獲取ioc容器中注入的bean(推薦),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對服務(wù)器之家網(wǎng)站的支持!

原文鏈接:https://blog.csdn.net/weixin_42021727/article/details/80318864

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 操av在线 | 一级欧美 | 日韩电影在线免费观看 | 欧美啪啪 | 免费无遮挡www小视频 | 国产精品久久久久一区二区三区 | 日韩欧美一区二区三区在线观看 | 黄视频免费| 四季久久免费一区二区三区四区 | 日韩免费 | 日本一区视频 | 精品福利网站 | 国产乱码精品一区二区三区av | 中文字幕亚洲一区 | 亚洲91| 中文av一区 | 国产福利电影 | 亚洲视频精品 | 日本一级淫片免费看 | 日韩高清在线观看 | 欧美日韩国产一区二区三区 | 国产96在线视频 | 欧美在线观看免费观看视频 | 精品国内 | 国产精品自拍视频 | 久久久成人动漫 | 风间由美av | 91精品国产福利在线观看 | 免费在线a | 免费观看一区二区三区毛片 | 久久国产精品一区 | 伊人激情 | 国产精品高潮呻吟久久av野狼 | 亚洲欧美日韩一区 | 久久99精品国产自在现线 | 日韩精品一区二区在线视频 | 久久国产精品99国产精 | 成人综合视频网 | 国产欧美精品区一区二区三区 | 国产亚洲精品美女久久久久久久久久 | 男女免费观看在线爽爽爽视频 |