<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    老妖的博客
    現(xiàn)實(shí)的中沒有幾個(gè)人能夠真為對(duì)方去死,甚至山盟海誓很快就會(huì)在金錢面前變的微不足道,這才是生活。沒有永遠(yuǎn)的愛,除了你的父母對(duì)你,當(dāng)然也就沒有永遠(yuǎn)的恨,更沒有永遠(yuǎn)的痛,時(shí)間是最好的治療大師,它會(huì)很快撫平你心靈上累累的傷痕。很多年以后你想起來時(shí),那些在你生命中洶涌來往的人群至多是個(gè)模糊的影子或者毫無意義的名字
    posts - 105,  comments - 171,  trackbacks - 0
    Everyone using spring is aware of the easy to handle ApplicationContext of Spring. There you define all your beans inside an XML and you can use them as AOP targets or plain javabeans. But what if you have AOP targets that are not known on Spring startup because they reside in a DB or some other storage. IMO there are two ways you can go:
    • Code something like a PropertyPlaceHolderConfigurer but acting on a Database, resulting in a DBPropertyPlaceholderConfigurer. The problem with this approach is that you dont have any datasource definitions at this point and it will be tricky to get it work this way.
    • The other approach is using a HotSwappableTargetSource as target of your ProxyFactoryBean. Here you simply code a DummyImplementation of the desired interface and replace the dummy on startup with the real implementation from the database or from whereever you want via reflection.
    I decide to use the HotSwappable direction to achieve the overall goal.
    example ApplicationContext definition
     1 <bean id="erpDataCollectorTarget" class="de.logentis.DummyERPDataCollector">
     2    <property name="clientManagerService" ref="clientManagerService"/>
     3    <property name="erpDataSource" ref="erpDataSource"/>
     4  </bean>
     5 <bean id="swapper" class="org.springframework.aop.target.HotSwappableTargetSource">
     6    <constructor-arg ref="erpDataCollectorTarget"/>
     7 </bean><bean id="erpDataCollector" class="org.springframework.aop.framework.ProxyFactoryBean">
     8     <property name="targetSource" ref="swapper"/>
     9     <property name="proxyInterfaces" value="de.logentis.ERPDataCollector"/>
    10     <property name="interceptorNames">
    11       <list>
    12          <value>jdoTransactionInterceptor</value>
    13       </list>
    14     </property>
    15 </bean>

    Look at the erpDataCollector bean, its a transactional proxy in my scenario. But as you can see, i dont use the "target" attribute with a concrete and not changeable bean definition but a "targetSource" pointing to a HotSwappableTargetSource. This hotswappable things get a default implementation which is nothing more than an empty implementation of the ERPDataCollector interface.

    Now when my application starts up, the internal spring plumbing comes first, after that i have a section where i setup my application with various defaults and other stuff. Somewhere in that section, i am doing this:

    1 // get the swapper bean from the Context, not shown here
    2 HotSwappableTargetSource swapper = getFromContext();
    3 // get the user defined class name from DB
    4 String classToLoad = getClassNameFromDB();
    5 Object o = getInstanceFromClassName(classToLoad);// swap the instances, removes the dummy and put the real impl
    6 // oldObject is the dummy and will be returned, normally you dont need
    7 // it anymore, but you can printout to be sure that it works like exptected
    8 Object oldObject = swapper.swap(o);

    At this point, the dummy is replaced with the class from the DB. Of course the DB holds only the full name of the class and it will get loaded via reflection. I left that out because this is plain java programming. Retrieving the swapper from the applicationContext is also trivial. One way would be to put this very code inside a bean which is controlled by Spring, this way you can just define a setter for the swapper and add the needed XML definition for that bean. If you run this from a ServletContextListener (best way to place bootstrap code), you can use something like this.
    do Hotswapping in ServletContextListener

     1 public class ApplicationInitFilter implements ServletContextListener {    public void contextInitialized(ServletContextEvent event) {
     2         WebApplicationContext webAppContext =
     3                WebApplicationContextUtils.getWebApplicationContext(
     4                                     event.getServletContext());        HotSwappableTargetSource swapper = 
     5                (HotSwappableTargetSource)webAppContext.getBean("swapper");        String classToLoad = getClassNameFromDB();
     6         Object o = getInstanceFromClassName(classToLoad);
     7         Object oldObject = swapper.swap(o);
     8     }    public void contextDestroyed(ServletContextEvent event) {
     9       // empty impl
    10     }}

    The interessting thing is, you can program an admin frontend for defining classes like this (its a german screenshot, but it should be readable for everyone): http://www.logemann.org/divs/dynclassdef.gif

    All in all, you can see that i used the HotSwappableTargetSource in a slightly different way than its used to be. I think the inventors created this class mainly to switch from one "real" implementation to another. In our context, we are switching from a dummy implementation to the real one but technically its the same of course. Thanks to Daniel Potter from the Spring community for mentioning the HotSwappable class, this really speeded up in finding my overall solution.

    posted on 2005-11-09 16:50 老妖 閱讀(1003) 評(píng)論(0)  編輯  收藏 所屬分類: spring

    <2005年11月>
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    常用鏈接

    隨筆分類(48)

    隨筆檔案(104)

    好友鏈接

    我的豆瓣

    積分與排名

    • 積分 - 220834
    • 排名 - 257

    最新評(píng)論

    閱讀排行榜

    主站蜘蛛池模板: 亚洲国产精品自产在线播放 | 黄色一级视频免费| 亚洲va在线va天堂va四虎| 美女黄网站人色视频免费国产| 久久成人a毛片免费观看网站| 人禽伦免费交视频播放| 亚洲一卡2卡三卡4卡无卡下载 | 亚洲黄色免费电影| 久久久久久国产a免费观看不卡| 亚洲人成色77777在线观看| 亚洲高清视频免费| 亚洲码国产精品高潮在线| 免费国产不卡午夜福在线| 亚洲成在人线aⅴ免费毛片| 91av视频免费在线观看| 三年片免费观看大全国语| 粉色视频免费入口| 国产亚洲一卡2卡3卡4卡新区| 亚洲宅男精品一区在线观看| 精品亚洲aⅴ在线观看| 久久亚洲高清观看| 亚洲午夜久久久久妓女影院 | 日韩av无码免费播放| 一本岛v免费不卡一二三区| 女bbbbxxxx另类亚洲| 亚洲精品久久无码av片俺去也| 亚洲中文字幕无码久久2020| 亚洲人成在线免费观看| 亚洲精品熟女国产| 亚洲精品国产啊女成拍色拍| 亚洲欧洲国产成人精品| 亚洲国产日韩女人aaaaaa毛片在线| 久久亚洲精品中文字幕| 久久国产亚洲高清观看| 亚洲美免无码中文字幕在线| 亚洲的天堂av无码| 亚洲一级高清在线中文字幕| 亚洲首页国产精品丝袜| 亚洲欧美日韩一区二区三区| 日韩国产精品亚洲а∨天堂免| 国产成人亚洲精品91专区高清|