功能
方便获取Spring IoC容器中的Bean调用方法getBean(String name)
import orgntextApplicationContext;
import orgntextsupportClassPathXmlApplicationContext;
import orgntextsupportFileSystemXmlApplicationContext;
public class SpringtUtil {
private static SpringtUtil instance = new SpringtUtil();
private static ApplicationContext context;
public static final String spring_context_configfile = nfigfile;
public static Object getBean(String name) {
return getContext()getBean(name);
}
public static ApplicationContext getContext() {
return SpringtUtilgetInstance(ntext;
}
public static SpringtUtil getInstance()
{
return instance;
}
private SpringtUtil()
{
try
{
String springContextFileName =PropertiesUtilgetProperty(spring_context_configfile);
//Systemoutprintln(springContextFileName);
context = new FileSystemXmlApplicationContext(springContextFileName);
} catch (Throwable t) {
tprintStackTrace();
}
}
public static void main(String[] args)
{
try {
UserService userService= (UserService)SpringtUtilgetBean(userService);
userServicetest(id name);
} catch (Exception e) {
eprintStackTrace();
}
}
}