Giter Club home page Giter Club logo

Comments (7)

agentgt avatar agentgt commented on July 22, 2024

Through some testing it looks like I need to also get hold of the AnnotationMethodHandlerAdapter which has a cache that needs to be cleared. The problem is that this class is often not even in the ApplicationContext because the DispatcherServlet will load the default from some properties and hold on to it in memory. Thus I need to get hold of the DispatcherServlet which seems very difficult to get hold of.

from hotswapagent.

agentgt avatar agentgt commented on July 22, 2024

I figured it out:

    Map<String, AbstractHandlerMethodMapping> mappings =
                BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, AbstractHandlerMethodMapping.class, true, false);
        for (Entry<String, AbstractHandlerMethodMapping> e : mappings.entrySet()) {
            sb.append(e.getKey()).append("<br/>");
            AbstractHandlerMethodMapping am = e.getValue();
            out.println(am.getClass());
            Field f = AbstractHandlerMethodMapping.class.getDeclaredField("handlerMethods");
            f.setAccessible(true);
            ((Map)f.get(am)).clear();
            f = AbstractHandlerMethodMapping.class.getDeclaredField("urlMap");
            f.setAccessible(true);
            ((Map)f.get(am)).clear();
            am.afterPropertiesSet();
        }

I'll make the change on my fork.

from hotswapagent.

smigielski avatar smigielski commented on July 22, 2024

I've installed dcevm with Hotswap agent {0.1-beta4}. For my test spring boot application when I change RequestMapping value or add the new method to the controller class it does not reflect the changes online. Any changes with components are immediately visible after reload.

Logs from reloading:

HOTSWAP AGENT: 12:34:47.828 DEBUG (org.hotswap.agent.plugin.spring.ResetSpringStaticCaches) - Unable to clear nonSingletonBeanNamesByType cache (is Ok for pre 3.2 Spring version)
HOTSWAP AGENT: 12:34:47.828 DEBUG (org.hotswap.agent.plugin.spring.scanner.ClassPathBeanDefinitionScannerAgent) - Removing bean definition 'someController'
HOTSWAP AGENT: 12:34:47.829 DEBUG (org.hotswap.agent.plugin.spring.ResetBeanPostProcessorCaches) - Cache cleared: AutowiredAnnotationBeanPostProcessor.candidateConstructorsCache
HOTSWAP AGENT: 12:34:47.829 DEBUG (org.hotswap.agent.plugin.spring.ResetBeanPostProcessorCaches) - Cache cleared: AutowiredAnnotationBeanPostProcessor.injectionMetadataCache
HOTSWAP AGENT: 12:34:47.829 RELOAD (org.hotswap.agent.plugin.spring.scanner.ClassPathBeanDefinitionScannerAgent) - Registering Spring bean 'someController'
HOTSWAP AGENT: 12:34:47.829 DEBUG (org.hotswap.agent.plugin.spring.scanner.ClassPathBeanDefinitionScannerAgent) - Bean definition 'someController'
HOTSWAP AGENT: 12:34:47.898 INFO (org.hotswap.agent.plugin.spring.ResetRequestMappingCaches) - Spring: clearing HandlerMapping for class org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
2014-10-30 12:34:47.968  INFO 3058 --- [      Thread-32] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2014-10-30 12:34:47.969  INFO 3058 --- [      Thread-32] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2014-10-30 12:34:47.982  INFO 3058 --- [      Thread-32] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/test2],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto java.lang.String ga.museo.service.SomeController.home()
HOTSWAP AGENT: 12:34:47.986 DEBUG (org.hotswap.agent.plugin.spring.ResetSpringStaticCaches) - Unable to clear nonSingletonBeanNamesByType cache (is Ok for pre 3.2 Spring version)

I would appreciate any hints what should I try.

from hotswapagent.

skybber avatar skybber commented on July 22, 2024

smigielski: HotswapAgent supports only Spring 3.x-4.x versions

from hotswapagent.

smigielski avatar smigielski commented on July 22, 2024

But Spring Boot is using spring version 4.0. As you can see also ResetRequestMappingCaches is working properly. The only thing is that request mapper is not producing new mappings.

from hotswapagent.

agentgt avatar agentgt commented on July 22, 2024

I'll test out Spring 4 later this week.

There is sort of a major annoying issue with having multiple ApplicationContexts which is often the case with Spring MVC applications as there is a parent application context and then a child context created for the dispatcher servlet that will have almost the same component scanning. For example if you have the following component scanning:

parent context:

    <context:component-scan base-package="com.snaphop">
        <!-- Ignore controllers -->
        <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
    </context:component-scan>

dispatcher servlet context:

    <!-- The controllers are autodetected POJOs labeled with the @Controller annotation. -->
    <context:component-scan base-package="com.snaphop" use-default-filters="false">
        <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
    </context:component-scan>

What happens is the wrong SpringPlugin gets called (ie the application context and not the dispatcher context when you change a @Controller. This is a fundamental bug with the spring plugin in general in that it doesn't fully emulate Springs component scanning.

The way around this is to not have overlapping component scanning.

from hotswapagent.

skybber avatar skybber commented on July 22, 2024

fixed by @frankdavid

from hotswapagent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.