Has anyone used Spring framework much? the whole IoC and - TopicsExpress



          

Has anyone used Spring framework much? the whole IoC and Dependency injection is great and all, but it seems to give you some big problems - mainly that without IoC you can specify an arbitrary order in which to initialize your objects, where as with IoC it creates all the beans when you instantiate the ApplicationContext with the bean.xml file. So if you have any backward dependancies (ie basket of fruit - the basket knows what fruit it contains, but its useful for the fruit to know which basket they are in as well), it breaks because your beans are trying to reference something that hasnt been instantiated yet. One workaround I did was to just to get rid of all of my constructors and simply use getters and setters so the order in which things are initialized by spring is irrelevant - but this is just bad because not using constructors to explicity state mandatory fields seems like a bad idea in the long run. second workaround Ive thought about is tricking Spring into using setters, but making the setters do more than set so if I need to do some processing I can do it there - again this is a really crude solution and it doesnt really let me control the order either other than after constructors. third workaround was to have multiple application contexts, so I have a bean.xml for one set of beans and otherbeans.xml for classes that must be insantiated AFTER the ones in beans.xml - however this creates reference problems, beans in otherbeans.xml cant refer to beans in beans.xml So, is there a way to force Spring to instantiate things in a particular order instead of an undefined order?
Posted on: Thu, 07 Aug 2014 04:46:06 +0000

Trending Topics



Recently Viewed Topics




© 2015