import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

/**
 * 工具类-spring bean*/
public class BeanUtil {
    private static WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();

    /**
     * 根据bean名称获取
     * 
     * @param name
     * @return
     */
    public static Object getBean(String name) {
        return ctx.getBean(name);
    }
}

 



 

使用方法

PluginsAccountDao pluginsAccountDao = (PluginsAccountDao) BeanUtil.getBean("pluginsAccountDao");

 

也可以获取service

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案