java - How can I ensure Spring constructs a bean once -


i have complex enterprise environment multiple projects depending on each other. configuration handled spring , includes crazy number imports , not.

looks default spring ok constructing bean same name more once. particularly, in case of multiple spring contexts. each context own instance of same singleton bean. singleton not singleton in spring architects' minds...

unfortunately, in case there's bean can never created more once.

is there way enforce spring checking upon bean whether it's been created , not try call constructor again?

particularly, bean creates ehcache's cachemanager inside , fails because cachemanager same name can't created twice.

    <bean id="cacheservice" class="somepackage.cacheserviceimpl">         <constructor-arg index="0" value="/somepackage/ehcache.xml" />     </bean> 

i don't have control on cacheserviceimpl code. can change configuration around it.

different spring application contexts don't know each other. far each context concerned, object is singleton. however, sounds don't want there multiple contexts.

how creating contexts? application should create single instance of applicationcontext (probably in main or somewhere nearby). else needs application context should have injected or made applicationcontextaware.

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-instantiation

you mention "complex enterprise environment". what's worked best work having single project manage spring. assuming projects being run in same application (otherwise spring can't you), there's project starts off. us, that's project built war , deployed our server.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -