黑马程序员技术交流社区
标题:
关于Spring框架
[打印本页]
作者:
肖亚光
时间:
2013-1-15 16:24
标题:
关于Spring框架
本帖最后由 可乐咖啡厅 于 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
复制代码
请问这是什么原因呢
作者:
yong230
时间:
2013-1-15 16:34
把xml文件中这句去了试试: factory-method="PersonServiceBean"
作者:
肖亚光
时间:
2013-1-15 16:37
yong230 发表于 2013-1-15 16:34
把xml文件中这句去了试试: factory-method="PersonServiceBean"
嗯 我问的就是去了是成功的 加上就不成功了 为什么
呵呵
不过我已经解决了 因为方法名字我写错了 谢谢
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2