慕瓜5041502
2017-06-07 22:11
InjectionServiceImp:
@Service
public class InjectionServiceImpl implements InjectionService {
@Autowired
private InjectionDAO injectionDAO;
public void save(String arg) {
System.out.println("service接收参数:"+arg);
arg=arg+""+this.hashCode();
injectionDAO.save(arg);
}
InjectionDAOImpl:
@Repository
public class InjtctionDAOImpl implements InjectionDAO {
public void save(String arg) {
System.out.println("保存数据"+arg);
}
}
Test:
public class Test {
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("spring-inject.xml");
InjectionService service=(InjectionService)ctx.getBean("injectionServiceImpl");
service.save("这是要保存的数据");
}
这样还是会找不到bean怎么回事?
问题不在这里,问题在于spring-inject.xml中 component-scan的 base-package路径和@Service所在路径不一致
不是找不到xml,如果找不到就会提示FileNoFoundException了
是不是xml文件的位置 试试classpath:spring-inject.xml
Spring入门篇
268787 学习 · 963 问题
相似问题