oJianDanGuo 2015-06-26 02:01 采纳率: 0%
浏览 1522

Spring自动装配,求大神答疑

小弟最近刚学的spring 自动装配有点问题请教:
这个是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"
xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
< context:component-scan base-package="cm.itcast"/>
< /beans>

接口:package cm.itcast.customer;
import org.springframework.stereotype.Service;
public interface CustomerDao {

public void save();

}

实现类:
package cm.itcast.customer.impl;
import org.springframework.stereotype.Service;
import cm.itcast.customer.CustomerDao;
@Service
public class CustomerDaoBean implements CustomerDao {

public void save(){
    System.out.println("我是customer save方法");
}

}

调用:
package junit.test;

import javax.annotation.Resource;
import cm.itcast.customer.CustomerDao;

public class Maintest {
@Resource
private CustomerDao customerDao;

public static void main(String args[]){
    Maintest maintest =new Maintest();
    maintest.test();
}

public void test(){
    customerDao.save(); 
}

}
空指针错误 求大神答疑。

  • 写回答

3条回答

  • 忧郁的小飞猪 2015-06-26 02:08
    关注

    注解方式,配置文件里配置PackagesToScan

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名