首页 > 编程语言 > 详细

Java静态方法中使用注入类

时间:2019-05-16 14:52:13      阅读:692      评论:0      收藏:0      [点我收藏+]
package com.test.controller;

import com.test.dao.TeacherMapper;
import com.test.model.TeacherEntity;
import net.sf.json.JSONArray;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.PostConstruct;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:dispatcher-servlet.xml"})
public class test {
    @Autowired
    TeacherMapper teacherMapper;

    private static test factory;

    @PostConstruct
    public void init() {
        factory = this;
    }
    
    public static void demo(){

      List<TeacherEntity> teacherList =factory.teacherMapper.getList();
      System.out.println(JSONArray.fromObject(teacherList));
    }
}

 

Java静态方法中使用注入类

原文:https://www.cnblogs.com/hanmian4511/p/10875186.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!