Hi
Here's my scenario. I have a class that checks a map to see if instance of ClassAlgo exists. If not it does new ClassAlgo, stores that in the Map and continues.
I'd LOVE that instances of class Algo be handles by Spring (so long as EACH instance is unique) as I want to tu benefit from the DAO stuff and even being able to use the 'ant style' placeholders to set up that instance with default (user-defined) variables.
Sample Java code: (in SomeOrganiser.java)
Spring Code / Configs:Code:// this key can change every request (but I may only have a few dozen in my app worse case. // algo map is a HashMap<String, ClassAlgo> as a field / attribute of the SomeOrganiser class. ClassAlgo algo = this.algoMap.get( someKey ); if ( algo == null ) { algo = new ClassAlgo( someKey ); this.algoMap.put( someKey, algo ); } // From here on out we use algo as normal.
And these placeholders would be picked up from the .propeties file as so:Code:<bean id="OrganizerClass" class="com.foo.bar.SomeOrganiser"/> <!-- What do I do here to get my ALgoMap setup for my ClassAlgo instances if I dont know how many I need OR the key they will be represented by. --> </bean> <bean id="ClassAlgo" class="com.foo.bar.ClassAlgo"> <property name="registeredHosts" value="${registered.hosts}"/> <property name="interval" value="${interval}"/> </bean>
Code:registered.hosts=http://foo.com/myurl|http://bar.com/myOtherUrl interval=1000


Reply With Quote
