当前位置: 代码迷 >> Java Web开发 >> Spring 有关问题 求解
  详细解决方案

Spring 有关问题 求解

热度:1587   发布时间:2013-02-25 21:17:25.0
Spring 问题 求解
package junit.test;


import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.itcast.service.PersonService;

public class SpringTest {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test public void instanceSpring(){
ApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml");
PersonService personService=(PersonService)ctx.getBean("personService");
personService.save();
}
}
 


2012-6-26 10:30:09 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1d1acd3: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1d1acd3]; startup date [Tue Jun 26 10:30:09 CST 2012]; root of context hierarchy
2012-6-26 10:30:09 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
2012-6-26 10:30:10 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@1d1acd3]: org.springframework.beans.factory.support.DefaultListableBeanFactory@12d15a9
2012-6-26 10:30:10 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12d15a9: defining beans [personService]; root of factory hierarchy
2012-6-26 10:30:10 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12d15a9: defining beans [personService]; root of factory hierarchy


------解决方案--------------------------------------------------------
beans.xml 配置的问题

PersonService personService=(PersonService)ctx.getBean("personService");
能获取到吗?
  相关解决方案