Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483798
  • 博文数量: 1496
  • 博客积分: 79800
  • 博客等级: 大将
  • 技术积分: 9940
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 13:22
文章分类

全部博文(1496)

文章存档

2011年(1)

2008年(1495)

我的朋友

分类:

2008-09-09 17:11:31

     import org.springframework.context.ApplicationContext;

    import org.springframework.context.support.ClassPathXmlApplicationContext;

    import org.springframework.context.support.FileSystemXmlApplicationContext;

    public class SpringtUtil {

      private static SpringtUtil instance = new SpringtUtil();

      private static ApplicationContext context;

      public static final String spring_context_configfile = "spring.context.configfile";

      public static Object getBean(String name) {

          return getContext().getBean(name);

      }

      public static ApplicationContext getContext() {

            return SpringtUtil.getInstance().context;

     }

        public  static SpringtUtil getInstance()

        {

            return instance;

        }

        private SpringtUtil()

        {

          try

            {

                 String springContextFileName =PropertiesUtil.getProperty(spring_context_configfile);

                 //System.out.println(springContextFileName);

                 context = new FileSystemXmlApplicationContext(springContextFileName);

            } catch (Throwable t) {

                t.printStackTrace();

            }

        }

      public static void main(String[] args)

      {

         try {

             UserService userService= (UserService)SpringtUtil.getBean("userService");

            userService.test("id", "name");

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    }


--------------------next---------------------

阅读(140) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~