HotswapProjects / HotswapAgent

Java unlimited redefinition of classes at runtime.
GNU General Public License v2.0
2.36k stars 493 forks source link

Update xml sql in mybatis + spring boot project error and will not take effect #550

Closed wallfacers closed 3 months ago

wallfacers commented 6 months ago

Environmental Information: java version: jdk1.8.0_181 dcevm:jdk8u181+2 HotswapAgent:1.4.2-SNAPSHOT

VM options: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -XXaltjvm=dcevm -javaagent:D:\develop\java\source\HotswapAgent\hotswap-agent\target\hotswap-agent.jar=propertiesFilePath=D:\downloads\hotswap-agent.properties

operation: Change what the arrow executes 1 to 2, and then perform hot deployment image

Error message; HOTSWAP AGENT: 00:21:00.847 ERROR (org.hotswap.agent.plugin.spring.reload.SpringBeanReload) - Failed to invoke PostProcessorRegistrationDelegate java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokePostProcessorRegistrationDelegate(SpringBeanReload.java:666) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokeBeanFactoryPostProcessors(SpringBeanReload.java:646) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.doReload(SpringBeanReload.java:296) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.reload(SpringBeanReload.java:259) at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.doReload(SpringChangedAgent.java:204) at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.reloadAll(SpringChangedAgent.java:192) at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.reload(SpringChangedAgent.java:143) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hotswap.agent.plugin.spring.reload.SpringChangedReloadCommand.executeCommand(SpringChangedReloadCommand.java:54) at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:43) Caused by: java.lang.NullPointerException at org.mybatis.spring.mapper.MapperScannerConfigurer.processPropertyPlaceHolders(MapperScannerConfigurer.java:386) at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:354) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:142) ... 17 more

HOTSWAP AGENT: 00:21:00.847 INFO (org.hotswap.agent.plugin.spring.reload.SpringBeanReload) - ##### [1th] finish reloading 'org.springframework.beans.factory.support.DefaultListableBeanFactory@5ef6fd7f', it cost 7ms HOTSWAP AGENT: 00:21:00.848 ERROR (org.hotswap.agent.plugin.spring.reload.XmlsChangedCommand) - Error invoking method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hotswap.agent.plugin.spring.reload.SpringChangedReloadCommand.executeCommand(SpringChangedReloadCommand.java:54) at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:43) Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokeBeanFactoryPostProcessors(SpringBeanReload.java:655) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.doReload(SpringBeanReload.java:296) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.reload(SpringBeanReload.java:259) at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.doReload(SpringChangedAgent.java:204) at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.reloadAll(SpringChangedAgent.java:192) at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.reload(SpringChangedAgent.java:143) ... 6 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokePostProcessorRegistrationDelegate(SpringBeanReload.java:666) at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokeBeanFactoryPostProcessors(SpringBeanReload.java:646) ... 11 more Caused by: java.lang.NullPointerException at org.mybatis.spring.mapper.MapperScannerConfigurer.processPropertyPlaceHolders(MapperScannerConfigurer.java:386) at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:354) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:142) ... 17 more

Error causeļ¼š Org. Mybatis. Spring. Mapper. MapperScannerConfigurer creates a temporary DefaultListableBeanFactory for placeholder substitution, And org. Hotswap. Agent. The plugin. Spring. Reload. SpringChangedAgent. SpringChangeAgents cache the temporary DefaultListableBeanFactory, in file change happened, Triggering a reload will cause the newly created bean not to follow the normal spring initialization process image

Another problem area: A configuration should be recreated before calling the buildSqlSessionFactory method of the sqlSessionFactoryBean spring bean. Otherwise, the xml file found loaded in the buildSqlSessionFactory method implementation will not be loaded again image

image

Test case: https://github.com/wallfacers/hotswap-agent-demo

Related issue: https://github.com/HotswapProjects/HotswapAgent/issues/538

wallfacers commented 6 months ago

@skybber help ~

homejim commented 3 months ago

https://github.com/homejim/HotswapAgent/releases/tag/1.4.2.1-SNAPSHOT

This package works correctly and resolves the issue.

skybber commented 3 months ago

fixed by @homejim in https://github.com/homejim/HotswapAgent/releases/tag/1.4.2.1-SNAPSHOT