package com.ssh.framework.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public final class SpringTool implements ApplicationContextAware { private static ApplicationContext applicationContext = null; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { if (SpringTool.applicationContext == null) { SpringTool.applicationContext = applicationContext; } } public static ApplicationContext getApplicationContext() { return applicationContext; } //传入实体类的全名 public static <T> Object getBean(Class<T> class1) { return getApplicationContext().getBean(class1); } }
public static SyncTimesLogService syncTimesLogService= (SyncTimesLogService) SpringTool.getBean(SyncTimesLogService.class);