12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package cn.com.qmth.ac.bean;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.core.ResolvableType;
- import org.springframework.stereotype.Component;
- @Component
- public class SpringContextHolder implements ApplicationContextAware {
- private static ApplicationContext ctx = null;
- @Override
- public void setApplicationContext(ApplicationContext ctx) {
- SpringContextHolder.ctx = ctx;
- }
- public static ApplicationContext getApplicationContext() {
- return ctx;
- }
- public static Object getBean(String name) {
- return ctx.getBean(name);
- }
- public static <T> T getBean(String name, Class<T> requiredType) {
- return ctx.getBean(name, requiredType);
- }
- public static <T> T getBean(Class<T> requiredType) {
- return ctx.getBean(requiredType);
- }
- public static Object getBean(String name, Object... args) {
- return ctx.getBean(name, args);
- }
- public static <T> T getBean(Class<T> requiredType, Object... args) {
- return ctx.getBean(requiredType, args);
- }
- public static boolean containsBean(String name) {
- return ctx.containsBean(name);
- }
- public static boolean isSingleton(String name) {
- return ctx.isSingleton(name);
- }
- public static boolean isPrototype(String name) {
- return ctx.isPrototype(name);
- }
- public static boolean isTypeMatch(String name, ResolvableType typeToMatch) {
- return ctx.isTypeMatch(name, typeToMatch);
- }
- public static boolean isTypeMatch(String name, Class<?> typeToMatch) {
- return ctx.isTypeMatch(name, typeToMatch);
- }
- public static Class<?> getType(String name) {
- return ctx.getType(name);
- }
- public static String[] getAliases(String name) {
- return ctx.getAliases(name);
- }
- }
|