java.lang.IllegalArgumentException異常處理的一種方法


我遇到的問題

用spring注解來加載bean,都是一個簡單的了,但是還是報了這樣一個錯java.lang.IllegalArgumentException

網上查了一下,說是jdk版本要1.7的,然后我就改了,就好了。

Person.java

1 package com.xiaostudy.service;
2 
3 import org.springframework.stereotype.Component;
4 
5 @Component("person")
6 public class Person {
7     
8 }

applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xsi:schemaLocation="http://www.springframework.org/schema/beans 
 6                               http://www.springframework.org/schema/beans/spring-beans.xsd
 7                               http://www.springframework.org/schema/context 
 8                               http://www.springframework.org/schema/context/spring-context.xsd">
 9 
10     <context:component-scan base-package="com.xiaostudy.service"></context:component-scan>
11 </beans>

測試類Test.java

 1 package com.xiaostudy.service;
 2 
 3 import org.springframework.context.ApplicationContext;
 4 import org.springframework.context.support.ClassPathXmlApplicationContext;
 5 
 6 import com.xiaostudy.service.Person;
 7 
 8 public class Test {
 9 
10     public static void main(String[] args) {
11         ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
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.IllegalArgumentException

 

解決問題

1、把eclipse的jdk調整為1.7

2、新建項目的jdk選擇1.7


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM