gpt4 book ai didi

java - 升级到 Java 7 后 Spring (3.2.0) ConfigurationClassEnhancer 中出现 Stackoverflow 错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:46:20 25 4
gpt4 key购买 nike

我们有几个 @Configuration 注解的类,该应用程序在 sun-jdk-6 上运行良好,但升级到 oracle-jdk-7 后发生了 SO 错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManagerPeerProviderFactory' defined in class path resource [com/egnyte/filestore/cache/CacheManagerPeerProviderConfigurationProvider.class]: Instantiation of bean failed; nested exception is 
org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object com.egnyte.filestore.cache.CacheManagerPeerProviderConfigurationProvider.get()] threw exception; nested exception is java.lang.StackOverflowError
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:297)
at com.egnyte.filestore.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9.get(<generated>)
at com.egnyte.filestore.cache.CacheManagerPeerProviderConfigurationProvider.get(CacheManagerPeerProviderConfigurationProvider.java:22)
at com.egnyte.filestore.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9.CGLIB$get$0(<generated>)
at com.egnyte.filestore.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9$$FastClassByCGLIB$$1a8904d5.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:285)
at com.egnyte.filestore.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9.get(<generated>)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
[SNAP...]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:297)
at foo.bar.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9.get(<generated>)
at foo.bar.cache.CacheManagerPeerProviderConfigurationProvider.get(CacheManagerPeerProviderConfigurationProvider.java:22)
at foo.bar.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9.CGLIB$get$0(<generated>)
at foo.bar.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9$$FastClassByCGLIB$$1a8904d5.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:285)
at foo.bar.cache.CacheManagerPeerProviderConfigurationProvider$$EnhancerByCGLIB$$6b65bac9.get(<generated>)
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029)

请注意,foo.bar.cache.CacheManagerPeerProviderConfigurationProvider.get(CacheManagerPeerProviderConfigurationProvider.java:22) 指向带有 @Configuration 注释的一行代码,而不是实际的 get() 实现。

默认代理模式为“否”。这个类没有什么奇特的:

@Configuration
class CacheManagerPeerProviderConfigurationProvider implements Provider<Foo<?>> {

@Inject
private List<Pair<String, Integer>> peers;

@Override
@Bean(name = CACHE_MANAGER_PEER_PROVIDER_FACTORY)
public Foo<?> get() {
return new Foo(peers);
}
}

这是 Spring 中的错误吗?是否可以禁用增强器?

最佳答案

好的,所以这肯定是 Spring 中的一个错误。

要解决此问题,请删除 Provider<>接口(interface),因此使 get()方法是一种常规方法,而不是被重写(似乎是 Provider 接口(interface)搞乱了内部 Spring 管道,而不是方法本身是重写)。使您的依赖项与 jsr-330 兼容就这么多了。

@Configuration
class CacheManagerPeerProviderConfigurationProvider
//implements Provider<Foo<?>>
{

@Inject
private List<Pair<String, Integer>> peers;

//@Override
@Bean(name = CACHE_MANAGER_PEER_PROVIDER_FACTORY)
public Foo<?> get() {
return new Foo(peers);
}
}

有效!

作为替代解决方案,更改 @Configuration@Component@Named

@Named
class CacheManagerPeerProviderConfigurationProvider implements Provider<Foo<?>>
{

@Inject
private List<Pair<String, Integer>> peers;

@Override
@Bean(name = CACHE_MANAGER_PEER_PROVIDER_FACTORY)
public Foo<?> get() {
return new Foo(peers);
}
}

已解决 in SPR-11830

关于java - 升级到 Java 7 后 Spring (3.2.0) ConfigurationClassEnhancer 中出现 Stackoverflow 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23931742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com