首页 > 学院 > 开发设计 > 正文

杂记

2019-11-08 01:03:34
字体:
来源:转载
供稿:网友

1.获取sPRing容器生成的对象

目标类

@Component("test")public class Test{private String name = "目标类";} 消费者public class  TestController extends BaseController{   @Resource   private Test test;   public void testService(){System.out.println(test.name);   }}消费者2public class TestFilter implements Filter {    private Test test;    @Override    public void init(FilterConfig filterConfig) throws ServletException {        //对需要用到的变量进行实例化    applicationContext context = WebApplicationContextUtils.getWebApplicationContext(filterConfig.getServletContext());        test= (Test)context.getBean("test");System.out.println(test.name);    }}


上一篇:箱子Ⅱ_线段树

下一篇:集合框架

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表