java.lang.IllegalArgumentException异常处理的⼀种⽅法
⽤spring注解加载bean,都是⼀个简单的了,但是还是报了这样⼀个错java.lang.IllegalArgumentException
记住我⽹上查了⼀下,说是jdk版本要1.7的,然后我就改了,就好了。
Person.java
1package com.xiaostudy.service;
2
3import org.springframework.stereotype.Component;
4
5 @Component("person")
6public class Person {
7
8 }
1<?xml version="1.0" encoding="UTF-8"?>
2<beans xmlns="/schema/beans"
3      xmlns:xsi="/2001/XMLSchema-instance"
4      xmlns:context="/schema/context"
5      xsi:schemaLocation="/schema/beans
6                              /schema/beans/spring-beans.xsd
7                              /schema/context
8                              /schema/context/spring-context.xsd">
9
10<context:component-scan base-package="com.xiaostudy.service"></context:component-scan>
11</beans>
测试类Test.java
1package com.xiaostudy.service;
2
3import t.ApplicationContext;
4import t.support.ClassPathXmlApplicationContext;
5
6import com.xiaostudy.service.Person;
7
8public class Test {
9
10public static void main(String[] args) {
11        ApplicationContext ac = new ClassPathXmlApplicationContext("l");
12        Person person = ac.getBean("person", Person.class);
13        System.out.println(person);
14    }
15
16 }
错误信息
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to read candidate component class: file [E:\IT\spring3\demo9\bin\com\xiaostudy\service\Person.class]; nested exception is java.lang.IllegalArgu
解决问题
1、把eclipse的jdk调整为1.7
2、新建项⽬的jdk选择1.7