Announcement Announcement Module
Collapse
No announcement yet.
Problem with beans.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with beans.xml

    Hi,

    im very noob on Spring, and im having problems when running my application. These are my classes:

    PHP Code:
    public interface GreetingProvider {

        public 
    String getGreeting() ;
        

    PHP Code:
    public class MyGreetingProvider implements GreetingProvider {

        public 
    String getGreeting() {
            
            return 
    "Good Morning, World!";
            
        }
        
        


    PHP Code:
    public interface MessageProvider {

        public 
    String getMessage();
        
        public 
    void SetGreetingProvider(GreetingProvider provider);
        
        public 
    GreetingProvider getGreetingProvider();

    PHP Code:
    public class HelloWorldMessageProvider implements MessageProvider {
        
        private 
    GreetingProvider greetingProvider null;

        public 
    String getMessage() {

            return 
    getGreetingProvider().getGreeting();
        }

        public 
    void SetGreetingProvider(GreetingProvider provider) {
            
            
    this.greetingProvider provider ;
            
        }

        public 
    GreetingProvider getGreetingProvider() {
            
            return 
    this.greetingProvider ;
            
        }


    PHP Code:
    <?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="renderer" 
              class="com.javapassion.examples.StandardOutMessageRenderer">
            <property name="messageProvider" 
                      ref="provider"/>
        </bean>
        <bean id="provider" 
              class="com.javapassion.examples.HelloWorldMessageProvider">
            <property name="greetingProvider" 
                      ref="greeting"/>
        </bean>
           <bean id="greeting"
                 class="com.javapassion.examples.MyGreetingProvider">
        </bean>
    </beans>
    When i try to run app throws me this error:

    PHP Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationExceptionError creating bean with name 'renderer' defined in class path resource [beans.xml]: Cannot resolve reference to bean 'provider' while setting bean property 'messageProvider'nested exception is org.springframework.beans.factory.BeanCreationExceptionError creating bean with name 'provider' defined in class path resource [beans.xml]: Error setting property valuesnested exception is org.springframework.beans.NotWritablePropertyExceptionInvalid property 'greetingProvider' of bean class [com.javapassion.examples.HelloWorldMessageProvider]: Bean property 'greetingProvider' is not writable or has an invalid setter methodDoes the parameter type of the setter match the return type of the getter?
        
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
        
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
        
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
        
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        
    at com.javapassion.examples.HelloWorldSpringWithDIXMLFile.getBeanFactory(HelloWorldSpringWithDIXMLFile.java:18)
        
    at com.javapassion.examples.HelloWorldSpringWithDIXMLFile.main(HelloWorldSpringWithDIXMLFile.java:11)
    Caused byorg.springframework.beans.factory.BeanCreationExceptionError creating bean with name 'provider' defined in class path resource [beans.xml]: Error setting property valuesnested exception is org.springframework.beans.NotWritablePropertyExceptionInvalid property 'greetingProvider' of bean class [com.javapassion.examples.HelloWorldMessageProvider]: Bean property 'greetingProvider' is not writable or has an invalid setter methodDoes the parameter type of the setter match the return type of the getter?
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
        
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
        ... 
    16 more
    Caused by
    org.springframework.beans.NotWritablePropertyException: [B]Invalid property 'greetingProvider' of bean class [com.javapassion.examples.HelloWorldMessageProvider]: Bean property 'greetingProvider' is not writable or has an invalid setter methodDoes the parameter type of the setter match the return type of the getter?[/B]
        
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1038)
        
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:914)
        
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
        
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
        ... 
    24 more 
    Words in bold, i guess where is the problem, but i do not have idea about resolve it.

    What's the problem?

    Many thanks!

  • #2
    Hi,

    I believe that the issue might be in the SetGreetingProvider method. Please change it to setGreetingProvider and it should work. Remember that java is case sensitive. Please let me know if it helps.

    Comment


    • #3
      Originally posted by preze5 View Post
      Hi,

      I believe that the issue might be in the SetGreetingProvider method. Please change it to setGreetingProvider and it should work. Remember that java is case sensitive. Please let me know if it helps.
      That was the problem. Im idiot!

      So many thanks!!

      Comment

      Working...
      X