Skip to content

使用热部署启动Spring项目时创建Bean失败 #229

@baoyonghua

Description

@baoyonghua

bug内容
在使用热部署功能来启动应用时,出现了预期之外的错误。其中导致Bean创建失败的关键错误为:java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"。关于堆栈详细见下。

版本信息

  • DebugTools版本: 4.5.2
  • Spring版本: 4.3.2.RELEASE
  • Java版本:JDK8

错误堆栈

2026-01-28 17:47:49.822 [] ERROR com.alibaba.dubbo.container.Main -  [DUBBO] Error creating bean with name 'complianceDecRemoteService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageBizService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageManager': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageSendHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retryManager': Injection of resource dependencies failed; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static", dubbo version: 2.0.1, current host: 172.31.197.255
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceDecRemoteService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageBizService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageManager': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageSendHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retryManager': Injection of resource dependencies failed; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
	at com.alibaba.dubbo.container.spring.SpringContainer.start(SpringContainer.java:45)
	at com.alibaba.dubbo.container.Main.main(Main.java:85)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageBizService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageManager': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageSendHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retryManager': Injection of resource dependencies failed; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318)
	... 15 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'complianceMessageManager': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageSendHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retryManager': Injection of resource dependencies failed; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318)
	... 29 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaMessageSendHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retryManager': Injection of resource dependencies failed; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318)
	... 43 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retryManager': Injection of resource dependencies failed; nested exception is java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318)
	... 57 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater.doCreate(EnhancerProxyCreater.java:154)
	at io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater.create(EnhancerProxyCreater.java:103)
	at io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater.createProxy(EnhancerProxyCreater.java:91)
	at io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.ProxyReplacer.register(ProxyReplacer.java:106)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318)
	... 71 common frames omitted
Caused by: java.lang.IllegalAccessException: Class io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater can not access a member of class HotswapAgentSpringBeanProxy_1796692748 with modifiers "private static"
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
	at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
	at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
	at java.lang.reflect.Method.invoke(Method.java:491)
	at io.github.future0923.debug.tools.hotswap.core.plugin.spring.getbean.EnhancerProxyCreater.doCreate(EnhancerProxyCreater.java:120)
	... 81 common frames omitted

如何复现
通过堆栈内容,我们可以发现,Spring Bean的依赖链路为:complianceDecRemoteService -> complianceMessageBizService -> complianceMessageManager -> kafkaMessageSendHelper -> retryManager

这几个Bean的内容如下所示:
1、ComplianceDecRemoteService

@Service("complianceDecRemoteService")
public class ComplianceDecRemoteServiceImpl implements ComplianceDecRemoteService {

    @Resource
    private ComplianceMessageBizService complianceMessageBizService;
    
    // 一些其余的public实例方法
    // ...
}

2、ComplianceMessageBizService

@Service
@Slf4j
public class ComplianceMessageBizService {

    @Resource
    private TradeBillService tradeBillService;

    @Resource
    private AssetChangeRecordService assetChangeRecordService;

    @Resource
    private ComplianceMessageManager complianceMessageManager;

    @Resource
    private RetryManager retryManager;
    
    // ... 一些其余的public以及private实例方法
}

3、ComplianceMessageManager

@Service
@Slf4j
public class ComplianceMessageManager {

    @Resource
    private KafkaMessageSendHelper kafkaMessageSendHelper;

    @Resource
    private CsnowflakeIdGenerator csnowflakeIdGenerator;

    @Resource
    private AccountIntegration accountIntegration;

    // ... 一些其余的public以及private实例方法
}

4、KafkaMessageSendHelper

@Component
@Slf4j
public class KafkaMessageSendHelper {

    @Resource
    private KafkaProducer kafkaProducer;
    
    @Resource
    private RetryManager  retryManager;

    // ... 一些其余的public以及private实例方法
}

5、RetryManager

@Slf4j
@Component
public class RetryManager {

    @Value("${retry.task.save.location}")
    private String taskSaveLocation;

    private RetryTemplate<RetryTaskParam> retryTemplate;

    // 一些使用 @Resource 注解的字段

    @PostConstruct
    public void init() {
         // 一个初始化方法用于完成对RetryTemplate的初始化操作
    }

   // 一些其余的实例方法
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions