今天,我已尝试从2.0.6.RELEASE->2.1.1.RELEASE
升级我们的应用程序,但由于以下原因,它不再启动:
org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'org.springframework.context.config.internalBeanConfigurerAspect' defined in class path resource [org/springframework/context/annotation/aspectj/SpringConfiguredConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.context.annotation.aspectj.SpringConfiguredConfiguration; factoryMethodName=beanConfigurerAspect; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/context/annotation/aspectj/SpringConfiguredConfiguration.class]] for bean 'org.springframework.context.config.internalBeanConfigurerAspect': There is already [Root bean: class [org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=aspectOf; initMethodName=null; destroyMethodName=null] bound.
at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:894)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:274)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
最初,我认为这是由于spring-data中的错误所致,但已在此版本(Spring Bean Overriding throws error in JpaAuditingRegistrar)中得到修复。
当我调试启动顺序时,我可以看到JpaAuditingRegistrar
首先注册了一个名称为org.springframework.context.config.internalBeanConfigurerAspect
的bean,然后下一个导致使用该名称注册bean的下一个类是{{1 }}。
还有什么我可以调查解决的? 我渴望不仅允许覆盖Bean,而且这是唯一的出路吗?
一些相关的spring配置类:
AopConfig
SpringConfiguredConfiguration
JpaConfig
@Configuration
@EnableSpringConfigured
public class AopConfig {
/**
* Ensure that all critical aspects have been configured.
* This method will blow up if they are not.
*/
@PostConstruct
public void postConstruct() {
Aspects.aspectOf(AnnotationBeanConfigurerAspect.class);
}
}
应用
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@EnableJpaRepositories(repositoryBaseClass = BaseJpaDaoImpl.class, basePackages = "com.xxx")
@EnableJpaAuditing(auditorAwareRef = "auditorProvider", dateTimeProviderRef = "auditingDateTimeProvider")
@EntityScan("com.xxx")
@Configuration
public class JpaConfig {
@NotNull
@Bean
public AuditorAware<String> auditorProvider() {
return new JpaAuditorAwareImpl();
}
@NotNull
@Bean(name = "auditingDateTimeProvider")
public DateTimeProvider auditingDateTimeProvider() {
return () -> Optional.of(ZonedDateTime.now());
}
}
其他信息:
@SpringBootApplication(scanBasePackages = "com.xxx")
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
@EnableAsync
@EnableScheduling
public class Application extends SpringBootServletInitializer { ... }
的输出:
https://gist.github.com/oliverhenlich/69a253e253dfd7c0189fc472f00705ad