spring工具类
Posted popopopopo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring工具类相关的知识,希望对你有一定的参考价值。
spring工具类获取bean编写
package com.cloudiip.security.utils; import org.springframework.stereotype.Component; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContext; import org.springframework.beans.BeansException; @Component public class SpringContextUtils implements ApplicationContextAware private static ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException SpringContextUtils.applicationContext=applicationContext; public static ApplicationContext getApplicationContext() return applicationContext; @SuppressWarnings("unchecked") public static <T> T getBean(Class name) throws BeansException if (applicationContext == null) return null; return (T)applicationContext.getBean(name);
调用方式:
PermissionService permissionService=SpringContextUtils.getBean(PermissionService.class);
以上是关于spring工具类的主要内容,如果未能解决你的问题,请参考以下文章
Spring工具类之PropertiesLoaderUtils