zoukankan      html  css  js  c++  java
  • 设置项目全局共享变量

    public class ContextUtil
      implements ApplicationContextAware
    {
      private static ApplicationContext appContext = null;
    
      public void setApplicationContext(ApplicationContext newAppContext)
        throws BeansException
      {
        appContext = newAppContext;
      }
    
      public static String getMessage(String code, Object[] params, String defaultDesc, Locale local) {
        return appContext.getMessage(code, params, defaultDesc, local);
      }
    
      public static <T> T getBean(String beanId, Class<T> clazz) throws BeansException {
        return appContext.getBean(beanId, clazz);
      }
    
      public static <T> T getBean(Class<T> clazz) throws BeansException {
        return appContext.getBean(clazz);
      }
    
      public static Object getBean(String beanId) throws BeansException {
        return appContext.getBean(beanId);
      }
    
      public static Cap4jUserInfo getLoginUser() {
        Object userInfo = null;
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if ((securityContext != null) && (securityContext.getAuthentication() != null)) {
          userInfo = securityContext.getAuthentication().getPrincipal();
          if (userInfo instanceof Cap4jUserInfo)
            return ((Cap4jUserInfo)userInfo);
        }
    
        return null;
      }
    
      public static ServletContext getServletContext() {
        return ((WebApplicationContext)appContext).getServletContext();
      }
    
      public static boolean isLoginCheck() {
        Cap4jInvocationSecurityMetadataSourceService medadataSource = (Cap4jInvocationSecurityMetadataSourceService)appContext.getBean("cap4jSecurityMetadataSource");
        return medadataSource.isLoginCheck();
      }
    
      public static boolean isUrlCheck() {
        Cap4jInvocationSecurityMetadataSourceService medadataSource = (Cap4jInvocationSecurityMetadataSourceService)appContext.getBean("cap4jSecurityMetadataSource");
        return medadataSource.isUrlCheck();
      }
  • 相关阅读:
    使用StreamHttpResponse和FileResponse下载文件的注意事项及文件私有化
    Django中@login_required用法简介
    Django之template
    单链表反转的原理和python代码实现
    两个队列实现栈,两个栈实现队列
    Linux--5 mariadb和redis的安装
    Linux--4
    Linux--3
    Linux--2 Linux之文档与目录结构、shell基本命令
    Linux--1 初识
  • 原文地址:https://www.cnblogs.com/mingforyou/p/4259738.html
Copyright © 2011-2022 走看看