2

Ok so I have a custom scope that works in a server environment. I'm trying to write some unit tests and in the case of the unit tests I want these beans to be singleton since it's too complicated to mock everything necessary to make the custom scope work.

I just want to do something like this

<!-- spring-test.xml -->
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
    <property name="scopes">
        <map>
            <entry key="myCustomScope" value-ref="singletonScope"/>
        </map>
    </property>
</bean> 

I want to override my custom scope in the junit test and just have it be singleton. However there doesn't seem to be a SingletonScope class as it seems quite embedded in the framework, being the default and all.

Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
rozner
  • 580
  • 2
  • 5
  • 11

1 Answers1

1

I think it is relatively easy to write a Scope implementation that behaves like singleton scope, especially if you don't particularly care about destruction callbacks (but even then not that difficult). I assume for testing purposes you care more about object creation than destruction so it should be just a matter of calling and caching the value from the ObjectFactory that you get handed in Scope.get().

Dave Syer
  • 56,583
  • 10
  • 155
  • 143