Announcement Announcement Module
Collapse
No announcement yet.
Value can't be changed in bean extended from AbstractController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Value can't be changed in bean extended from AbstractController

    Hi,

    I have a bean to return xml response so I extended my bean from AbstractController. After code is running in debug mode, I changed value to String urlReq = "diffValue"
    but this value cant' be taken in handleRequestInternal(). I tried putting scope="prototype" in that bean, but didn't work either. It is Spring 2.0. Any idea? Thanks!

    <bean id="earthController" class="action.EarthController" />

    public class EarthController extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String urlReq = "value";
    //logic to return xml response
    return null;
    }

    }

  • #2
    When posting code please use [ code][/code ] tags without the spaces ofcourse.

    And I have no idea what you mean or try to achieve...

    Comment


    • #3
      Hi kkus,

      I am also confused about what you mean, but it doesn't even look like you're using Spring to configure your 'earthController' bean (i.e. your not injecting any dependencies into it). What are you trying to achieve?

      Comment


      • #4
        Sorry for missing put <code> there.

        What I need is send a http://localhost/test.html, the following code will respond with sending back a xml file. In my debug I noticed if I change any value for a variable in handleRequestInternal() this change can't be reflected. That confused me. This is a very simple test and I am using Spring 2.0 (MVC), why can't I see new value for that variable? Thanks!

        Code:
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                <property name="mappings">
                    <props>
                        <prop key="/test.htmll">earthController</prop>
                    </props>
                </property>
        </bean>
        
        <bean id="earthController" class="action.EarthController" />
        
        public class EarthController extends AbstractController {
        
        @Override
        protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String urlReq = "value";
        //logic to return xml response
        return null;
        }
        
        }

        Comment


        • #5
          I still don't have a clue on what you want to achieve...

          Comment


          • #6
            Originally posted by kkus View Post
            In my debug I noticed if I change any value for a variable in handleRequestInternal() this change can't be reflected
            I think this is to vague for anyone to provide help. What variable are you changing? How are you changing it (in the code directly? via configuration?). What is not 'reflected'?

            I think it would be easier for you to post the code before changing and then post the code after changing so people can determine what you're trying to do.

            Comment


            • #7
              Sorry for confusion. For the following code, I put String urlReq = "value" first and set up a breakpoint there. Then I run app in debug mode. It shows me "value" when breakpoint is reached. Then I change String urlReq = "value2" and fire http request again. When breakpoint is reached again this time urlReq still equals to "value" rather than "value2". Why did it happen? Is it related to servlet thread? Thanks!

              Code:
              <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                      <property name="mappings">
                          <props>
                              <prop key="/test.htmll">earthController</prop>
                          </props>
                      </property>
              </bean>
              
              <bean id="earthController" class="action.EarthController" />
              
              public class EarthController extends AbstractController {
              
              @Override
              protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
              String urlReq = "value";
              //logic to return xml response
              return null;
              }
              
              }

              Comment


              • #8
                Originally posted by kkus View Post
                Then I change String urlReq = "value2" and fire http request again.
                Do you re-deploy your webapp? If you just change the value in your source code but don't rebuild and re-deploy the war, there will be no change in your webapp.

                Comment


                • #9
                  I just change the value in source code but don't rebuild and re-deploy the war. To my understanding, Java will take care of swapping changed class/method/variable to memory (is that called hot deployment?) so my new value should be reflected when breakpoint is reached. I have experienced this kind of change a lot in my daily work(app of Spring+Hibernate+JBoss), not sure why it doesn't work with AbastractController. I have code which extends from SimpleFormController and I have no problem seeing new changed value in debug mode without rebuilding/redeployment. Any hints? Thanks!

                  Comment


                  • #10
                    Originally posted by kkus View Post
                    For the following code, I put String urlReq = "value" first and set up a breakpoint there. Then I run app in debug mode. It shows me "value" when breakpoint is reached. Then I change String urlReq = "value2" and fire http request again. When breakpoint is reached again this time urlReq still equals to "value" rather than "value2".
                    The urlReq is a local variable. You change only its value for this local scope. As soon as the second request hits the breakpoint it is in its original state of course.

                    Or are you modifying the source code on the fly? Hot code replacement does not always work ...

                    Joerg

                    Comment


                    • #11
                      I modified its value on-the-fly and expect to see hot-swap work in this case, but not. I guess that is because I start Tomcat from its bootstrap and Tomcat doesn't implement redefineClasses() method of the
                      java.lang.instrument.Instrumentation interface, so new value doesn't take effect immediately after change.

                      Comment


                      • #12
                        I'm not that familiar with hot-code replacement that I know how exactly it works. I have no idea about the Instrumentation class. But it used to work for me to a limited extent.

                        From your description I still don't get though whether you are modifying code on the fly or just changing a value. If it is the latter the next request will of course have the old value again.

                        Joerg

                        Comment


                        • #13
                          I'm not into the whole hot code replacement thing; I'd rather rebuild so I know my change took effect. It might be slower, but you don't deal with issues like this

                          Comment


                          • #14
                            Originally posted by Arthur Loder View Post
                            I'm not into the whole hot code replacement thing; I'd rather rebuild so I know my change took effect. It might be slower, but you don't deal with issues like this
                            Tomcat/ Eclipse/ the JVM tell me reliably when they could not do the code replacement

                            And in the few cases were it works (more or less only changing method-local implementations if at all) I'm happy that I don't need to restart the application since it usually takes the one or the other minute.

                            The only stupid thing that can happen is that everything works fine after the replacement. For whatever reason I now restart the server forgetting to redeploy - and run in already fixed issues again ...

                            Joerg

                            Comment

                            Working...
                            X