Announcement Announcement Module
Collapse
No announcement yet.
not so Singletons, and Cyclic references Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • not so Singletons, and Cyclic references

    I am having problems keeping my Singletons as singletons. I have a cyclic reference between two beans (references are runtime - through interfaces, not concrete)

    I have seen a number if discussions related to cyclic references, but it is not clear if cyclic runtime references between beans (through interfaces) is legal in Spring. In my experiments, i was able to get it to autowire most of the references, but some were not wired. A number of beans used the constructor to assign references, whilst others used setters. All beans have been defined singleton="true"

    I can guess that using bean constructors to specify references can limit flexibility (but helps maintain "integrity")

    One problem is that each time it mentions a bean in the attached output, it actually INSTANTIATES the bean using the relevant constructor. Is this a side effect of the cyclic referencing? (so we get 2 x 'marketModelService', 3 x 'connectorService', 3 x 'aiConnector' etc)

    Running with debug on suggest that "uninitialised" references will not be used in other beans. Is this why I am getting multiple "singletons"?

    Is cycling referencing (at runtime through interfaces) supported in Spring (1.2) or just considered "Evil" I am aware of the lifecycle issues of the dependencies.


    The cyclic dependency is as follows:

    connectorService contains connectors
    aiConnecter is a connector and is used in the construction of connectorService
    aiConnector references orderService, marketModelService, tradingModelService
    marketModelService references connectorService


    Using autowiring, i get the following output from log4j:

    xml.XmlBeanFactory - Creating shared instance of singleton bean 'auditService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'blotterService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'connectorService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'aiConnector'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'orderService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'marketModelService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'currencyPairHelper'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'jmsConnector'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'marketModelService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'connectorService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'aiConnector'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'tradingModelService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'persistenceService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'perspectiveService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'positionService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'stpService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'tradingModelService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'connectorService'
    xml.XmlBeanFactory - Creating shared instance of singleton bean 'aiConnector'
Working...
X