com.star.spring.SpringBeanUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
some utility class for java develop
The newest version!
package com.star.spring;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
/**
* 获取spring容器托管的bean
*
* @author starhq
*
*/
public final class SpringBeanUtil {
/**
* 锁
*/
private static Object obj = new Object();
private SpringBeanUtil() {
}
/**
* 按名字查找bean
*/
public static Object getBeanFromSpring(final String beanName) {
synchronized (obj) {
final WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
return wac.getBean(beanName);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy