本帖最后由 可乐咖啡厅 于 2013-1-15 16:37 编辑
这是xml文件- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
- <bean id="personService" class="cn.itheima.service.impl.PersonServiceBean"/>
- <bean id="personService2" class="cn.itheima.service.impl.PersonServiceBeanFactory"
- factory-method="PersonServiceBean"/>
- </beans>
复制代码 一开始只有一个<bean>的时候运行是正确的
但是现在多加了一个 就运行不过去了- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import cn.itheima.service.PersonService;
- public class SpringTest {
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
- @Test public void instanceSprint(){
- ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
- // ItHeimaClassPathXmlApplicationContext ctx = new ItHeimaClassPathXmlApplicationContext("beans.xml");
- PersonService personService = (PersonService)ctx.getBean("personService");
- // PersonService personService2 = (PersonService)ctx.getBean("personService2");
- personService.save();
- // personService2.save();
- }
- }
复制代码 就这样即使我注掉要实例第二个。照样不能运行。
也就是我的xml文件多加了一个<bean>后就不能运行了
报错是这样的- 2013-1-15 16:21:09 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
- 信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@5973ea]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1556d12
- 2013-1-15 16:21:09 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
- 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1556d12: defining beans [personService,personService2]; root of factory hierarchy
- 2013-1-15 16:21:09 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
- 信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1556d12: defining beans [personService,personService2]; root of factory hierarchy
复制代码 请问这是什么原因呢
|
|