Announcement Announcement Module
Collapse
No announcement yet.
bean class ending with Component suffix Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • bean class ending with Component suffix

    Hi, anyone noticed that the bean class should not end with "Component" if you like to get beans instantiated from it:

    <bean id="IHS2" class="com.ibm.ibiis.modules.infrastructure.spring .Component2">
    <property name="name">
    <value>http</value>
    </property>
    <property name="status">
    <value>c</value>
    </property>
    </bean>
    will work but:

    <bean id="IHS2" class="com.ibm.ibiis.modules.infrastructure.spring .Component">
    <property name="name">
    <value>http</value>
    </property>
    <property name="status">
    <value>c</value>
    </property>
    </bean>

    fails with an exception:

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'betismIHS2' defined in resource loaded through InputStream: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'status' of bean class [com.ibm.ibiis.modules.infrastructure.spring.Compon ent]: Bean property 'status' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'status' of bean class [com.ibm.ibiis.modules.infrastructure.spring.Compon ent]: Bean property 'status' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:670)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:572)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:737)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:764)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:753)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1061)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:857)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:378)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:537)
    ...

    Component class looks as follows:
    package com.ibm.ibiis.modules.infrastructure.spring;
    public class Component {
    public String name=null;
    public char status;
    /**
    *
    */
    public Component() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @return
    */
    public String getName() {
    return name;
    }

    /**
    * @param string
    */
    public void setName(String string) {
    name = string;
    }

    /**
    * @return
    */
    public char getStatus() {
    return status;
    }

    /**
    * @param c
    */
    public void setStatus(char c) {
    status = c;
    }

    }


    The only thing I did was rename the Component class to Component2 and back as I changed xml. Spring version is 1.2.8.

  • #2
    I have no 1.2.8 version at hand. But I could not reproduce this with versions 1.2.2, 2.0rc2 and 2.0 final.

    Regards,
    Andreas

    Comment


    • #3
      Just created a little test trying to reproduce it and with 2.0 I cannot reproduce the mentioned behavior.

      Code:
      package nl.deinum.nametest;
      
      public class Component {
          public String name=null;
          public char status;
          /**
          *
          */
          public Component() {
              super();
          }
      
          /**
          * @return
          */
          public String getName() {
          return name;
          }
      
          /**
          * @param string
          */
          public void setName(String string) {
          name = string;
          }
      
          /**
          * @return
          */
          public char getStatus() {
          return status;
          }
      
          /**
          * @param c
          */
          public void setStatus(char c) {
          status = c;
          }
      
          }

      Code:
      package nl.deinum.nametest;
      
      public class Component2 {
          public String name=null;
          public char status;
          /**
          *
          */
          public Component2() {
              super();
          }
      
          /**
          * @return
          */
          public String getName() {
          return name;
          }
      
          /**
          * @param string
          */
          public void setName(String string) {
          name = string;
          }
      
          /**
          * @return
          */
          public char getStatus() {
          return status;
          }
      
          /**
          * @param c
          */
          public void setStatus(char c) {
          status = c;
          }
      
          }
      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-2.0.xsd">	
      
      	<bean id="cmp1" class="nl.deinum.nametest.Component">
      		<property name="name" value="component1"/>
      		<property name="status" value="c"/>
      	</bean>
      
      	<bean id="cmp2" class="nl.deinum.nametest.Component2">
      		<property name="name" value="component2"/>
      		<property name="status" value="c"/>
      	</bean>
       </beans>
      Code:
      package nl.deinum.nametest;
      
      import org.springframework.context.ApplicationContext;
      import org.springframework.context.support.ClassPathXmlApplicationContext;
      
      public class ComponentTest {
          /**
           * @param args
           */
          public static void main(String[] args) {
              ApplicationContext ctx = new ClassPathXmlApplicationContext("nl/deinum/nametest/appctx.xml");
              
              Component o1 = (Component) ctx.getBean("cmp1");
              Component2 o2 = (Component2) ctx.getBean("cmp2");
              
              System.out.println("Name1: " + o1.getName());
              System.out.println("Name2: " + o2.getName());
          }
      }
      No errors on loading, just neatly executing the code, displaying the names of the components.

      Comment


      • #4
        again

        Hi, I would like to point out few things about my environment:
        IBM WSAD 5.1.2

        Context is loaded a bit different then posted in replys:
        GenericApplicationContext appContext = new GenericApplicationContext();
        InputStreamResource isr=new InputStreamResource(getClass().getClassLoader().ge tResourceAsStream("com/ibm/ibiis/modules/infrastructure/spring/ConfigInfrastructure.xml"));
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext);
        xmlReader.loadBeanDefinitions(isr);
        Component2 comp=(Component2)appContext.getBean("IHS2");
        System.out.println("Component name is "+comp.getName());

        XML is the following:
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "file:///e:/spring-beans.dtd">

        <!-- "http://www.springframework.org/dtd/spring-beans.dtd"> -->

        <beans>
        <description>This is main configuration file for infrastructure. </description>


        <bean id="IHS2" class="com.ibm.ibiis.modules.infrastructure.spring .Component2">
        <property name="name">
        <value>http</value>
        </property>
        <property name="status">
        <value>c</value>
        </property>
        </bean>
        </beans>

        This works and the output is:
        log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
        log4j:WARN Please initialize the log4j system properly.
        Component name is http

        When I change name back to Component it looks as follows:

        Code:
        GenericApplicationContext appContext = new GenericApplicationContext();
        InputStreamResource isr=new InputStreamResource(getClass().getClassLoader().ge tResourceAsStream("com/ibm/ibiis/modules/infrastructure/spring/ConfigInfrastructure.xml"));
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext);
        xmlReader.loadBeanDefinitions(isr);
        Component comp=(Component)appContext.getBean("IHS2");
        System.out.println("Component name is "+comp.getName());

        XML:
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "file:///e:/spring-beans.dtd">

        <!-- "http://www.springframework.org/dtd/spring-beans.dtd"> -->

        <beans>
        <description>This is main configuration file for infrastructure. </description>


        <bean id="IHS2" class="com.ibm.ibiis.modules.infrastructure.spring .Component">
        <property name="name">
        <value>http</value>
        </property>
        <property name="status">
        <value>c</value>
        </property>
        </bean>


        </beans>

        and the result:
        log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
        log4j:WARN Please initialize the log4j system properly.
        Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'IHS2' defined in resource loaded through InputStream: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'status' of bean class [com.ibm.ibiis.modules.infrastructure.spring.Compon ent]: Bean property 'status' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
        org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'status' of bean class [com.ibm.ibiis.modules.infrastructure.spring.Compon ent]: Bean property 'status' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:670)
        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:572)
        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:737)
        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:764)
        at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:753)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1061)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:857)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:378)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
        at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:537)
        ...


        I can recreate this when ever I want. I also tried deleting all .class files and rebuild the project but the error persists. I lost half of the day when I figured it out it is becuse of class name. I am sure that I am importing and referencing right package of Componentx class! I never seen any limitation on bean class name is documentation. Please try to initialize context using my code and see what happens. Thanks!

        Comment


        • #5
          That produces
          Code:
          org.springframework.beans.factory.BeanDefinitionStoreException: Passed-in Resource [resource loaded through InputStream] contains an open stream: cannot determine validation mode automatically. Either pass in a Resource that is able to create fresh streams, or explicitly specify the validationMode on your XmlBeanDefinitionReader instance.
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.detectValidationMode(XmlBeanDefinitionReader.java:449)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.getValidationModeForResource(XmlBeanDefinitionReader.java:438)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:357)
          	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
          However, using a ClassPathResource instead (which seems simpler anyway) does work (Spring 2.0).

          Try creating a simple standalone testcase (outside WSAD) that reproduces this problem. Maybe also try out a newer Spring version and see if the problem disappears then.

          Also for tracking classloading issues add the "-verbose:class" VM parameter on startup. That might reveal which "Component" class is actually loaded.

          Regards,
          Andreas

          Comment


          • #6
            I created an isolated environment outside WSAD (eclipse) using SUN java 1.4.2. and could not reproduce the problem. It works ok then:
            Environment is not 100% the same as in WSAD where I use different java version.

            E:\src>java -classpath e:/src/bin;xml-apis.jar;xercesImpl.jar;spring-support.jar;spring-orm.jar,spring-dao.jar;spring-cor
            e.jar;spring-context.jar;spring-beans.jar;spring-beans.dtd;spring-aop.jar;log4j-1.2.8.jar;jakarta-oro-2.0.8.jar;commons-l
            ogging.jar;commons-lang.jar;commons-httpclient-2.0.2.jar;commons-collections.jar;commons-beanutils.jar;activation.jar com
            .ibm.ibiis.modules.infrastructure.Spring

            log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
            log4j:WARN Please initialize the log4j system properly.
            Component name is http


            Once I switch to IBM java 1.4.1 the error reappears:
            E:\src>SET JAVA_HOME=F:\wsad_g_installed\runtimes\base_v51\ja va\jre

            E:\src>F:\wsad_g_installed\runtimes\base_v51\java\ jre\bin\java -fullversion
            java full version "J2RE 1.4.1 IBM Windows 32 build cn1411-20031011"

            E:\src>F:\wsad_g_installed\runtimes\base_v51\java\ jre\bin\java -classpath e:/src/bin;xml-apis.jar;xercesImpl.jar;spring-
            upport.jar;spring-orm.jar,spring-dao.jar;spring-core.jar;spring-context.jar;spring-beans.jar;spring-beans.dtd;spring-aop
            jar;log4j-1.2.8.jar;jakarta-oro-2.0.8.jar;commons-logging.jar;commons-lang.jar;commons-httpclient-2.0.2.jar;commons-coll
            ctions.jar;commons-beanutils.jar;activation.jar com.ibm.ibiis.modules.infrastructure.Spring
            log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
            log4j:WARN Please initialize the log4j system properly.
            Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'IHS2'
            defined in resource loaded through InputStream: Error setting property values; nested exception is org.springframework.b
            ans.NotWritablePropertyException: Invalid property 'status' of bean class [com.ibm.ibiis.modules.infrastructure.spring.C
            mponent]: Bean property 'status' is not writable or has an invalid setter method: Does the parameter type of the setter
            atch the return type of the getter?
            org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'status' of bean class [com.ibm.ibiis.modules.i
            frastructure.spring.Component]: Bean property 'status' is not writable or has an invalid setter method: Does the paramet
            r type of the setter match the return type of the getter?
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:670)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:572)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:737)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:764)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:753)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAuto
            ireCapableBeanFactory.java:1061)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCap
            bleBeanFactory.java:857)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapab
            eBeanFactory.java:378)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
            at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:537)
            at com.ibm.ibiis.modules.infrastructure.Spring.<init> (Spring.java:20)
            at com.ibm.ibiis.modules.infrastructure.Spring.main(S pring.java:25)
            E:\src>

            In WSAD I get the following trace of classloader before the error stack trace appears:
            [Loaded com.ibm.ibiis.modules.infrastructure.spring.Compon ent from file:/E:/IBIIS/WebContent/WEB-INF/classes/]
            [Loading superclass and interfaces of com/ibm/ibiis/modules/infrastructure/spring/Component]
            [Preparing com/ibm/ibiis/modules/infrastructure/spring/Component]
            which means that it works with right class. I spent too much time on this and I will workaround it using different class name and move on. Blah, what a problem!. Thank you all for your time!
            Last edited by mihael.j; Nov 2nd, 2006, 02:50 AM.

            Comment

            Working...
            X