常见错误之基础部分

来源:互联网 发布:多系统数据同步 编辑:程序博客网 时间:2024/05/20 23:38

java.lang.ArrayIndexOutOfBoundsException

角标越界错误

解决:要保证数组的下标在 0 ~ (长度-1) 之间


java.lang.NullPointerException

空指针异常

解决:找到引用变量,使其指向具体的某个堆中的内存地址


beans.factory.NoSuchBeanDefinitionException: No bean named 'userService' is defined

原因: Bean 对象 都处于当前工程不同包下...Spring  工程 进行Bean注册 必须 知道目标类注解 在哪个包下!告知spring 注解对哪些对象有效!

核心配置文件: 开启注解!   在applicationContext.xml引入<context>名称空间 才可以 开启注解扫描  

@Companent 注解才可以生效!   xsd-config.html  获取 context名称空间

引入context 名称空间

<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.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<!-- bean definitions here -->

<context:component-scan base-package="包名.service"  />

</beans>


0 0