Announcement Announcement Module
Collapse
No announcement yet.
How to refresh Spring bean configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to refresh Spring bean configuration

    Hi guys

    I searched Google and this forum for this topic already, but did not find something helpful.

    My application is split up into two different parts, the "middle-tier"(plain java with spring,hibernate) and the "web-tier"(tomcat appserver, spring).

    Now I would like to be able to refresh the spring bean configuration. I thought the best way to do it would be to have a JSF/JSP page on the web-tier with two buttons, one to refresh the middle-tier and the other to refresh the webtier. If the webtier is not running, it should be possible to refresh the spring bean configuration on the middletier using JMX.

    To you know a tutorial or something helpful? Spring Webflow is refreshed automatically by Eclipse hot deployment to tomcat

    Thanks!

    Remo

  • #2
    What is it specifically that you want to do? You can refresh an applicationContext but you're going to destroy and re-carete all the singleton beans.
    http://www.springframework.org/docs/...html#refresh()

    Comment


    • #3
      Sorry may be I wrote it somehow complicated.

      Let's say I have a backing bean for my JSF page. This backing bean is configured in a spring bean configuration like this:
      Code:
      <bean id="myBean" class="com.remo.myApplication.beans.MyBean"/>
      This bean looks like:

      Code:
      public class MyBean implements Serializable{
      
        public void doSomething(){
          System.out.println("hello I did something");
        }
      
      }


      Then I would like to have inject another bean into MyBean. Therefore, I have to change MyBean and the spring bean configuration.

      Code:
      <bean id="myBean" class="com.remo.myApplication.beans.MyBean">
        <property name="otherBean" ref="myOtherBean" />
      </bean>
      This bean looks like:

      Code:
      public class MyBean implements Serializable{
      
        MyOtherBean bean;
      
        public void setOtherBean(MyOtherBean bean){
          this.bean = bean;
        }
      
      
        public void doSomething(){
          System.out.println("hello I did something");
          bean.doSomething();
        }
      
      }
      The MyBean is deployed by eclipse hot deployment to tomcat. But the spring bean configuration isn't. Now I would like to refresh the spring bean configuration somehow.

      How is this possible?

      Thanks,
      Remo

      Comment


      • #4
        Let's say I have a backing bean that has a method like:

        Code:
        public void refreshSpringConfiguration(){
                ((ConfigurableApplicationContext)getApplicationContext()).refresh();
        }
        According to http://www.springframework.org/docs/....html#refresh()
        I would have to destroy all singletons. How Can I do this?

        Comment


        • #5
          I think the javadoc, is actually saying all singletons will be destroyed for you. The comment is basically telling implementors on this method what the expected behaviour should be. I don't think you have an issue here.

          Comment


          • #6
            Yes, the singletons configured in spring are destroyed. But I still get an exception saying a singleton exists. Does anybody know how to get ride of this?


            Code:
            net.wimpi.telnetd.BootException: Singleton already instantiated.
            	at net.wimpi.telnetd.TelnetD.createTelnetD(TelnetD.java:180)
            	at net.wimpi.telnetd.TelnetD.createTelnetD(TelnetD.java:199)
            	at net.wimpi.telnetd.TelnetD.main(TelnetD.java:238)
            	at com.swisslog.spoc7.product.web.handheld.telnet.TelnetDBean.setFileUrl(TelnetDBean.java:51)
            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            	at java.lang.reflect.Method.invoke(Method.java:585)
            	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:786)
            	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:606)
            	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
            	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74)
            	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.applyPropertyValues(AbstractBeanFactory.java:840)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1026)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:809)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
            	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
            	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
            	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273)
            	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
            	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
            	at com.swisslog.spoc7.product.web.jsf.controller.CommonController.refreshSpringConfiguration(CommonController.java:93)
            	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            	at java.lang.reflect.Method.invoke(Method.java:585)
            	at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
            	at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
            	at javax.faces.component.UICommand.broadcast(UICommand.java:106)
            	at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:274)
            	at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:250)
            	at org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:405)
            	at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
            	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
            	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            	at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:67)
            	at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:223)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            	at org.ajaxanywhere.AAFilter.doFilter(AAFilter.java:46)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            	at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
            	at com.swisslog.spoc7.product.web.security.SpocContextIntegrationFilter.doFilter(SpocContextIntegrationFilter.java:126)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
            	at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:108)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:193)
            	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
            	at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
            	at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            	at com.swisslog.spoc7.product.web.util.MdcIpFilter.doFilter(MdcIpFilter.java:50)
            	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
            	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
            	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
            	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
            	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
            	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
            	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
            	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
            	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
            	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
            	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
            	at java.lang.Thread.run(Thread.java:595)

            Comment


            • #7
              Where is the exception actually coming from, it appears to be "net.wimpi.telnetd.TelnetD". Is here a chance this doesn't get destroyed properly? Does it required a destruction lifecycle method specifying? There does seem to be a stop method on TelnetD, have you tried adding this?
              http://www.springframework.org/docs/...disposablebean

              Comment


              • #8
                how can you achieve this without destroying the bean

                I need a similar functionality, where changing the property file should make Spring reload values into the existing bean instances without destroying the objects and recreating them. How can we achieve this?

                Comment


                • #9
                  Couldn't you use JMX or simply reset the value on the bean?

                  Comment


                  • #10
                    Originally posted by karldmoore View Post
                    Where is the exception actually coming from, it appears to be "net.wimpi.telnetd.TelnetD". Is here a chance this doesn't get destroyed properly? Does it required a destruction lifecycle method specifying? There does seem to be a stop method on TelnetD, have you tried adding this?
                    http://www.springframework.org/docs/...disposablebean


                    Thanks, that one helped me a lot. I was able to null the singleton in the destroy method, now spring refresh works great!

                    Thanks dude!

                    Remo

                    Comment


                    • #11
                      Not a problem, glad it worked! Guess stuff just needed to be cleaned up properly.

                      Comment

                      Working...
                      X