History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-13855
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Sergey Vasiliev
Reporter: Taras Tielkes
Votes: 1
Watchers: 4
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Spring: good code red: special factory bean reference syntax

Created: 26 Jan 07 13:17   Updated: 06 Nov 08 23:25
Component/s: J2EE.Spring
Fix Version/s: Undefined

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 6,656
Fixed in build: 6,757
Severity: Medium


 Description  « Hide
See: http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-extension-factorybean

When referencing a factorybean, the special syntax "&factoryBeanId" can be used to obtain a reference to the factory (not to the product of the factory).

Sample code:

<bean id="test" class="foo.Bar">
    <property name="baz" ref="&amp;lfb"/>
  </bean>

  <bean id="lfb" class="org.springframework.beans.factory.config.ListFactoryBean">
    <property name="sourceList">
      <list>
        <value>foo</value>
        <value>bar</value>
      </list>
    </property>
  </bean>


 All   Comments   Work Log   Change History      Sort Order:
Taras Tielkes - 10 Apr 07 12:53
This is not fixed - please reopen.
This feature of spring is slightly obscure though, so it's certainly not an "M1" item (more like "nice to have in Selena Final").

Here's code that shows invalid warning:

public class FactoryUser {
    public void setFactory(FactoryBean factory) {
        System.out.println("received factory: " + factory);
    }
}
<bean id="someFactory" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
  <property name="serviceInterface" value="java.util.Set"/>
  <property name="serviceUrl" value="http://www.google.com/myClusteredSet"/>
</bean>

<bean id="factoryUser" class="foo.bar.FactoryUser">
  <property name="factory" ref="&amp;someFactory"/>
</bean>

Note that the dependency is of type FactoryBean, not java.util.Set (the factory product type).

Error shown is "Cannot resolve bean &someFactory". However, at runtime the configuration parses and runs as expected.


Taras Tielkes - 10 Apr 07 16:36
Small enhancement (when this gets implemented): completion after "&"/"&" could show only factoryBeans.