我们有几个@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中的错误吗?是否可以禁用增强器?
答案 0 :(得分:1)
好的,所以这肯定是Spring中的一个错误。
要解决这个问题,请删除Provider<>
界面,然后使get()
方法成为常规方法而不是覆盖(似乎是提供商界面正在弄乱内部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