方便獲取Spring IoC容器中的Bean
import orgntext
import orgntext
import orgntext
public class SpringtUtil {
private static SpringtUtil instance = new SpringtUtil();
private static ApplicationContext context;
public static final String spring_context_configfile =
public static Object getBean(String name) {
return getContext()
}
public static ApplicationContext getContext() {
return SpringtUtil
}
public static SpringtUtil getInstance()
{
return instance;
}
private SpringtUtil()
{
try
{
String springContextFileName =PropertiesUtil
//System
context = new FileSystemXmlApplicationContext(springContextFileName);
} catch (Throwable t) {
t
}
}
public static void main(String[] args)
{
try {
UserService userService= (UserService)SpringtUtil
userService
} catch (Exception e) {
e
}
}
}
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28304.html