this is the code in spring framwork i had an error see after codes if you know the solution please write down in the comments
Person class
package com.yousufArar.testsp;
public class Person {
private int id;
private String pName;
private String job;
private adresses adress;
public adresses getAdress() {
return adress;
}
public void setAdress(adresses adress) {
this.adress = adress;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getpName() {
return pName;
}
public void setpName(String pName) {
this.pName = pName;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
void display() {
System.out.println("id is : "+id+" "+"the name is : "+pName+" and the job is : "+job);
System.out.println(" the adress is : "+adress.infoAddress());}}
adress class
package com.yousufArar.testsp;
public class adresses {
private String phone;
private String email;
private String countery;
private String city;
private String street;
private String streetNo;
public adresses(String phone, String email, String countery, String city, String street, String streetNo) {
super();
this.phone = phone;
this.email = email;
this.countery = countery;
this.city = city;
this.street = street;
this.streetNo = streetNo;
}
public String infoAddress () {
return ( "phone: "+phone+ "email : "+email+"countery: "+countery+"city: "+city+ "street: "+street+ "streetNo: "+streetNo);
}
}
applicationConext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="add" class="com.yousufArar.testsp.adresses">
<property name=""> <value>"123456789"</value> </property>
<property name=""> <value>"y@gmail.com"</value> </property>
<property name=""> <value>"italia"</value> </property>
<property name=""> <value>"pisa"</value> </property>
<property name=""> <value>"fratello"</value> </property>
<property name=""> <value>"31"</value> </property>
</bean>
<bean id="p" class="com.yousufArar.testsp.Person">
<property name="id">
<value>1000</value>
</property>
<property name="pName">
<value>dani</value>
</property>
<property name="job">
<value>information</value>
</property>
<property name="adress" ref="add">
</property>
</bean>
</beans>
the error is
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
Offending resource: class path resource [applicationContext.xml]
Bean 'add'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Tag 'property' must have a 'name' attribute
Offending resource: class path resource [applicationContext.xml]
Bean 'add'
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:119)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:288)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:540)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:437)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:405)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition(DefaultBeanDefinitionDocumentReader.java:306)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:197)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:176)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:149)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:96)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:513)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:393)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:624)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at com.yousufArar.testsp.testp.main(testp.java:14)
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Tag 'property' must have a 'name' attribute
Offending resource: class path resource [applicationContext.xml]
Bean 'add'
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:119)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:111)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parsePropertyElement(BeanDefinitionParserDelegate.java:835)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parsePropertyElements(BeanDefinitionParserDelegate.java:705)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionElement(BeanDefinitionParserDelegate.java:525)
... 23 more
if you know the solution please write down in the comments to share with others
i found that i didn't put name attribute inside porperty of name="add"
<property name=""> <value>"123456789"</value> </property>
<property name=""> <value>"y@gmail.com"</value> </property>
<property name=""> <value>"italia"</value> </property>
<property name=""> <value>"pisa"</value> </property>
<property name=""> <value>"fratello"</value> </property>
<property name=""> <value>"31"</value> </property>
i put the names for all
<property name="phone"> <value>"123456789"</value> </property>
<property name="email"> <value>"y@gmail.com"</value> </property>
<property name="countery"> <value>"italia"</value> </property>
<property name="city"> <value>"pisa"</value> </property>
<property name="street"> <value>"fratello"</value> </property>
<property name="streetNo"> <value>"31"</value> </property>
but still have error
Oct 13, 2018 9:24:12 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'add' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yousufArar.testsp.adresses]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'add' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yousufArar.testsp.adresses]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1163)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:848)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:865)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at com.yousufArar.testsp.testp.main(testp.java:14)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yousufArar.testsp.adresses]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1261)
... 13 more
Caused by: java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
... 14 more
share your openinio with us
thank you
i found that i didn't put name attribute inside porperty of name="add"
<property name=""> <value>"123456789"</value> </property>
<property name=""> <value>"y@gmail.com"</value> </property>
<property name=""> <value>"italia"</value> </property>
<property name=""> <value>"pisa"</value> </property>
<property name=""> <value>"fratello"</value> </property>
<property name=""> <value>"31"</value> </property>
i put the names for all
<property name="phone"> <value>"123456789"</value> </property>
<property name="email"> <value>"y@gmail.com"</value> </property>
<property name="countery"> <value>"italia"</value> </property>
<property name="city"> <value>"pisa"</value> </property>
<property name="street"> <value>"fratello"</value> </property>
<property name="streetNo"> <value>"31"</value> </property>
but still have error
Oct 13, 2018 9:24:12 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'add' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yousufArar.testsp.adresses]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'add' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yousufArar.testsp.adresses]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1163)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:848)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:865)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at com.yousufArar.testsp.testp.main(testp.java:14)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yousufArar.testsp.adresses]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1261)
... 13 more
Caused by: java.lang.NoSuchMethodException: com.yousufArar.testsp.adresses.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
... 14 more
share your openinio with us
thank you
3 Comments
i change the name of property here
ReplyDeleteand put ut name="add" as in ref but still problem
i change the instructor in addresses class and replaced it by setter and getter
ReplyDeletebut give me this error
Invalid property 'add' of bean class [com.yousufArar.testsp.Person]: Bean property 'add' is not writable or has an invalid setter method. Did you mean 'id'?
Exception in thread "main"
after i put the getter and setter i return name attribute property
ReplyDeletehere to address in bean class ="p"
now all thing is good the result here
id is : 1000 the name is : dani and the job is : information
the adress is : phone: 123456789email : y@gmail.comcountery: italiacity: pisastreet: fratellostreetNo: 31