请教一个简单的问题

chl0707moming 2017-10-26 06:21:11
新学习spring框架,按照教程搭建spring环境,单元测试时最后的save方法没有运行,是怎么回事,求教
public class SpringTest {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void instanceSpring(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); // 实例化Spring容器
PersonService personService = (PersonService) ctx.getBean("personService"); // 从Spring容器取得bean
personService.save();
}
}
package cn.itcast.service;
public interface PersonService {
void save();
}
package cn.itcast.service.impl;
import cn.itcast.service.PersonService;
public class PersonServiceBean implements PersonService {
/* (non-Javadoc)
* @see cn.itcast.service.impl.PersonService#save()
*/
@Override
public void save(){
System.out.println("我是save方法");
}
}
//bean.xml文件
<bean id="presonService" class="cn.itcast.service.impl.PersonServiceBean"></bean>

输出:
十月 26, 2017 6:07:06 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@490d6c15: startup date [Thu Oct 26 18:07:06 CST 2017]; root of context hierarchy
十月 26, 2017 6:07:06 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
...全文
296 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rookiekk 2017-11-05
  • 打赏
  • 举报
回复
L_sliang 2017-11-05
  • 打赏
  • 举报
回复
1楼说的对,我也是新人,命名规范那些学到了,谢谢!!
public_TIM 2017-10-30
  • 打赏
  • 举报
回复
因为你没有实例化该对象,建议你使用注解的方式完成操作,而且你的命名很不规范,接口实现类一般在实现类后面加Impl。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧