大家好,我是春季初學者,我剛開始使用它。 我得到一個錯誤在Spring中創建bean時出錯
錯誤創建名稱爲豆‘問題’在類路徑資源定義爲「[組織/收集/ ApplicationContext2.xml]:指定3構造函數的參數,但沒有匹配的構造函數豆‘的問題’發現(提示:指定索引/型號/名稱參數進行簡單的參數,以避免類型歧義)」
我有兩個班月1日是問題,它包含一個構造函數問題和第二類是答案
我想創建參考的答案類,並插入問題類有陣列列表
我瞪着它,發現我需要指定類型。 我已經指定,但我仍收到錯誤
謝謝..
Question.java
package org.collection;
import java.awt.List;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
public class Question {
private int id;
private String name;
private ArrayList<String> answers;
//private HashSet<String> answers1;
public Question()
{
//Default constructor
}
public Question(int id,String name,ArrayList<String> answers)
{
super();
this.id=id;
this.name=name;
this.answers=answers;
}
public void display()
{
System.out.println("Id :"+id+"\nName :"+name);
System.out.println("Answers are");
Iterator<String> itr= answers.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
/*System.out.println("----------picking up the answers from HashSet---------");
Iterator<String> itr1=answers1.iterator();
while(itr1.hasNext())
{
System.out.println(itr1.next());
}
System.out.println("-------reached-----------");*/
}
}
Answer.java
package org.collection;
public class Answer {
private int id;
private String name;
private String by;
public Answer() {
// TODO Auto-generated constructor stub
}
public Answer(int id,String name,String by)
{
super();
this.id=id;
this.name=name;
this.by=by;
}
public String toString()
{
return "ID :"+id+"\nName"+name+"\nBy :"+by;
}
}
的ApplicationContext .xml2
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="ans1" class="org.collection.Answer">
<constructor-arg value="1" type="int"></constructor-arg>
<constructor-arg value="java is a progamming language hahahaha" type="java.lang.String"></constructor-arg>
<constructor-arg value ="varun" type="java.lang.String"> </constructor-arg>
</bean>
<bean id ="ans2" class="org.collection.Answer">
<constructor-arg value="2" type="int"></constructor-arg>
<constructor-arg value="java is a platfornm" type="java.lang.String"></constructor-arg>
<constructor-arg value ="Rahul" type="java.lang.String"></constructor-arg>
</bean>
<bean id="question" class= "org.collection.Question">
<constructor-arg value="111" type="int"></constructor-arg>
<constructor-arg value="What is java ?" type="java.lang.String"></constructor-arg>
<constructor-arg>
<list>
<ref bean="ans1"/>
<ref bean="ans2"/>
</list>
</constructor-arg>
</bean>
</beans>
您得到的錯誤是什麼? – 2015-03-25 06:59:02
作爲「Rahul」和「varun」的類型,您需要指定完全限定的類名(java.lang.String)而不是String。 – 2015-03-25 06:59:36
@KarthikPrasad在類路徑資源[org/collection/ApplicationContext2.xml]中定義名稱爲'question'的bean時出錯:指定了3個構造函數參數,但在bean'question'中找不到匹配的構造函數(提示:指定索引/類型/名稱參數對於簡單的參數,以避免類型歧義) – Varun 2015-03-25 07:00:13