zoukankan      html  css  js  c++  java
  • SpringUtil

    package cn.com.util;
    
    import java.util.Map;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServletRequest;
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    
    public class SpringUtil implements ApplicationContextAware {
    
        private static ApplicationContext applicationContext = null;
       
    
        public SpringUtil() {
        }
    
        public static void setApplicationContexts(ApplicationContext applicationContext) throws BeansException {
            SpringUtil.applicationContext = applicationContext;
        }
    
        public static ApplicationContext getApplicationContext() {
            return applicationContext;
        }
    
        public static <T> T getBean(String name) throws BeansException {
            return applicationContext.getBean(name);
        }
    
        public static Map<String, ?> getBeansOfType(Class<?> class1) {
            return applicationContext.getBeansOfType(class1);
        }
    
        public static <T> T getBean(Class<T> type) throws BeansException {
            return applicationContext.getBean(type);
        }
    
        public static <T> T getBean(String beanName, Class<T> type) throws BeansException {
            return applicationContext.getBean(beanName, type);
        }
    
        public static String getToken(HttpServletRequest request) {
            Cookie[] cookie = request.getCookies();
            if (cookie == null) {
                return null;
            } else {
                for(int i = 0; i < cookie.length; ++i) {
                    Cookie cook = cookie[i];
                    if (cook.getName().equals("SESSION") && !"".equals(cook.getValue() + "".trim())) {
                        return cook.getValue().toString();
                    }
                }
    
                return null;
            }
        }
    
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            SpringUtil.applicationContext = applicationContext;
        }
    }
  • 相关阅读:
    ▶ 0001 No application 'E:wwwgolog' found in your GOPATH
    beego路由
    go sync.WaitGroup
    idea修改filetype
    deepin添加设置快捷键
    mysql数据库被攻击
    linux桌面系统的约定
    deepin把vscode设为默认文本应用
    linux应用管理
    当你在工作中失去动力时该怎么办?
  • 原文地址:https://www.cnblogs.com/bevis-byf/p/14281488.html
Copyright © 2011-2022 走看看