发表新主题 回复该帖子
主题:Spring中遇到问题,请高手解答
gy93108083
帖子档案  楼主 Spring中遇到问题,请高手解答   Post by : 2008-09-28 07:08:28.0
  • 幼儿园
  • 幼儿园
  • UID:182
  • 主题:1
  • 帖子:1
  • 加为好友 加为好友    发送短信 发送短信
最近用Spring遇到一个问题



<beans>

        <bean name="mydao" class="com.app.dao.DAO"></bean>
        <bean name="myservice" class="com.app.service.Service"></bean>
       
</beans>



package com.app.dao;

public class DAO {

        public DAO() {
                super();
                System.out.println("create dao !!!!!");
        }
       
       
       

}



package com.app.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.app.dao.DAO;

public class Service {

        private static ApplicationContext context = null;
        static{
               
               
                new ClassPathXmlApplicationContext("applicationContext.xml");
                System.out.println("after create context!!! ");
        }
       
       
       
        public Service() {
                super();
                System.out.println("create Serice!!!!");
        }
       
        public void UseService(){
                System.out.println("before get dao!!!");
                DAO dao= (DAO)context.getBean("mydao");
                System.out.println("after get dao! ");
        }
       

}




package com.app.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {

        /**
         * @param args
         */
        public static void main(String[] args) {
                ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        }

}


这样的代码运行没有问题

但是,如果把service里改成




public class Service {

        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
       
        public Service() {
                super();
                System.out.println("create Serice!!!!");
        }
       
        public void UseService(){
                System.out.println("before get dao!!!");
                DAO dao= (DAO)context.getBean("mydao");
                System.out.println("after get dao! ");
        }
       

}


就会出现死循环,请问这是什么原因导致的??????????????????????????
返回页面顶部  

amen
2F Re:~   Post by : 2008-09-28 15:37:29.0
  • 幼儿园
  • 幼儿园
  • UID:15
  • 主题:4
  • 帖子:9
  • 加为好友 加为好友    发送短信 发送短信
不明白你这程序有什么用?Test那里又没有调用到其它方法,这有什么意义呢?
发帖时麻烦把结果也发上来看看。。
返回页面顶部  


CopyRight © 2008-2009 JavaWind.Net Studio All Rights Reserved
Powered By JWind.BBS Vesion 1.0.0 Beta1 Processed in 29 ms,0 (Queries)  Gzip enabled

WAP - 清除Cookies - 联系我们 - JavaWind.Net Studio - Archiver - TOP Valid XHTML 1.0 Transitional Valid CSS! 粤ICP备07511478号