Error:
Citar
8/02/2011 06:13:20 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@c1b531: display name [org.springframework.context.support.FileSystemXmlApplicationContext@c1b531]; startup date [Tue Feb 08 18:13:20 CST 2011]; root of context hierarchy
8/02/2011 06:13:20 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\Abel\Desktop\Ejemplo con Spring Inyeccion de Dependencias AplicationContext\Archivo.xml]
8/02/2011 06:13:20 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@c1b531]: org.springframework.beans.factory.support.DefaultListableBeanFactory@158b649
8/02/2011 06:13:20 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@158b649: defining beans [Clase1,Clase2]; root of factory hierarchy
8/02/2011 06:13:20 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@158b649: defining beans [Clase1,Clase2]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Clase1' defined in file [C:\Users\Abel\Desktop\Ejemplo con Spring Inyeccion de Dependencias AplicationContext\Archivo.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'VariableIndependienteB' of bean class [Independiente]: Bean property 'VariableIndependienteB' is not writable or has an invalid setter method. Did you mean 'variableIndependienteB'?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at Dependiente.main(Dependiente.java:8)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'VariableIndependienteB' of bean class [Independiente]: Bean property 'VariableIndependienteB' is not writable or has an invalid setter method. Did you mean 'variableIndependienteB'?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
... 16 more
Process completed.
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@c1b531: display name [org.springframework.context.support.FileSystemXmlApplicationContext@c1b531]; startup date [Tue Feb 08 18:13:20 CST 2011]; root of context hierarchy
8/02/2011 06:13:20 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\Users\Abel\Desktop\Ejemplo con Spring Inyeccion de Dependencias AplicationContext\Archivo.xml]
8/02/2011 06:13:20 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@c1b531]: org.springframework.beans.factory.support.DefaultListableBeanFactory@158b649
8/02/2011 06:13:20 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@158b649: defining beans [Clase1,Clase2]; root of factory hierarchy
8/02/2011 06:13:20 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@158b649: defining beans [Clase1,Clase2]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Clase1' defined in file [C:\Users\Abel\Desktop\Ejemplo con Spring Inyeccion de Dependencias AplicationContext\Archivo.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'VariableIndependienteB' of bean class [Independiente]: Bean property 'VariableIndependienteB' is not writable or has an invalid setter method. Did you mean 'variableIndependienteB'?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at Dependiente.main(Dependiente.java:8)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'VariableIndependienteB' of bean class [Independiente]: Bean property 'VariableIndependienteB' is not writable or has an invalid setter method. Did you mean 'variableIndependienteB'?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
... 16 more
Process completed.
Siendo este mi context:
Código
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="Clase1" class="Independiente"> <property name="VariableIndependienteB" ref="Clase2"/> </bean> <bean id="Clase2" class="IndependienteB"></bean> </beans>
Y estas mis Clases:
Clase Dependiente:
Código
import javax.swing.*; import org.springframework.context.support.FileSystemXmlApplicationContext; public class Dependiente { FileSystemXmlApplicationContext FSXObj = new FileSystemXmlApplicationContext("Archivo.xml"); //InterfaceRelacion Obj = (InterfaceRelacion)FSXObj.getBean("Clase1"); //JOptionPane.showMessageDialog(null,"Uno" + Obj.GetNombreUsuario()); } }
Clase Independiente
Código
public class Independiente implements InterfaceRelacion { public IndependienteB VariableIndependienteB; public void setVariableIndependienteB(IndependienteB VariableIndependienteB){ this.VariableIndependienteB=VariableIndependienteB; } return VariableIndependienteB.GetNombreUsuario(); } }
Interface InterfaceRelacion
Código
Clase IndependienteB
public interface InterfaceRelacion { }
Código
public class IndependienteB implements InterfaceRelacion { return "Abel"; } }