Announcement Announcement Module
Collapse
No announcement yet.
Issue getting a bean dependancy of another bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mickknutson
    started a topic Issue getting a bean dependancy of another bean

    Issue getting a bean dependancy of another bean

    I have a bean that has a setter/getter for another bean.

    Code:
        <bean id="generateClaimIDImpl"
              class="org.delta.esp.dap.c2.claim.GenerateClaimIDImpl"
              depends-on="propertiesFile">
            <property name="propertiesFile">
                <ref bean="propertiesFile" />
            </property>
        </bean>
    
        <bean id="propertiesFile"
              class="org.delta.esp.dap.c2.claim.PropertiesFile">
            <constructor-arg>
                <value>/generate-claim-id.properties</value>
            </constructor-arg>
        </bean>
    generateClaimIDImpl keeps getting initialized with a null propertyFile


    Can someone help me understand why and how to fix this?

  • Mark Fisher
    replied
    Spring provides support for creating a Properties object from a properties file location with PropertiesFactoryBean (or in Spring 2.x+ you can use the 'util: properties' element). Check out http://static.springframework.org/sp...til-properties for an example of each. Hopefully this can simplify your code by eliminating the custom object that it looks like you are creating there.

    Leave a comment:


  • mickknutson
    replied
    I found the issue. The bean was getting created outside of the spring Context by just calling new Bean();

    Is there a way to force the creation of the bean to happen inside th Context?

    Leave a comment:


  • mickknutson
    replied
    I also read somewhere about creating the propertyFile object like:

    Code:
        <bean id="propertiesFile"
              class="org.delta.esp.dap.c2.claim.PropertiesFile">
            <constructor-arg type="java.io.InputStream">
                <value>classpath:generate-claim-id.properties</value>
            </constructor-arg>
        </bean>
    But the injected Object is still null

    Leave a comment:

Working...
X