Comments (7)
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.
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.
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.
smigielski: HotswapAgent supports only Spring 3.x-4.x versions
from hotswapagent.
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.
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.
fixed by @frankdavid
from hotswapagent.
Related Issues (20)
- cannot create release HOT 1
- Caused by: compile error: no such class: ManagedBean
- No match for watchkey event
- Does the solution of JetBrainsRuntime 11 + HotswapAgent can work? HOT 1
- Getting error every build HOT 1
- Errors thrown when starting jbr_jcef-17.0.7 Minecraft Paper server. HOT 4
- IntelliJ plugin or other easy way to launch from IntelliJ HOT 1
- Can HotswapAgent support add @Resource/@Autowired fields in springboot based project? HOT 6
- JacksonPlugin ConcurrentModificationException
- What is the ProxyReplacerTransformer in the Spring plugin used for? HOT 1
- HotswapAgent IDEA plugin Could not identify JBR17's dcevm HOT 1
- bug: my Spring Boot project will OOM after running for a day
- Can not get a JavaCompiler instance with jbr_17.0.7 HOT 1
- Executing ReloadJavaProxyCommand caused an infinite loop HOT 5
- What is the ProxyReplacerTransformer in the Spring plugin used for? HOT 1
- How do I run this from gradle / openjdk? (Exception on changes) HOT 2
- NullPointerException: Cannot invoke "java.net.URL.getFile()" because the return value of "org.hotswap.agent.javassist.ClassPool.find(String)" is null HOT 3
- Application run failed HOT 2
- java.lang.NullPointerException: Cannot invoke "java.net.URL.getFile()" because the return value of "org.hotswap.agent.javassist.ClassPool.find(String)" is null
- Some API cannot work well in spring 6, such as org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#postProcessPropertyValues is removed in spring6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hotswapagent.