1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package cn.com.qmth.archive.utils;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.core.ResolvableType;
- import org.springframework.stereotype.Component;
- /**
- * spring context holder.
- *
- */
- @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);
- }
- }
|