Skip to content

MVC auto-configuration does not back off when <mvc:annotation-driven> is used resulting in a BeanDefinitionOverrideException for mvcContentNegotiationManager #16396

@thomas-worm-datev

Description

@thomas-worm-datev

Using spring boot 2.1.3:

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.3.RELEASE</version>
	</parent>`

with

		<!-- 
		
		***********************
		* Spring dependencies *
		***********************
		
		-->
	
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework.ws</groupId>
			<artifactId>spring-ws-core</artifactId>
		</dependency>
		
		<dependency>
			<groupId>org.springframework.ws</groupId>
			<artifactId>spring-ws-support</artifactId>
		</dependency>
		
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
		</dependency>

		<!-- 
				
		************************
		* Swagger dependencies *
		************************
		
		-->

		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-core</artifactId>
			<version>1.5.9</version>
		</dependency>

		<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-core</artifactId>
			<version>2.0.7</version>
		</dependency>
		
		<!-- 
		
		*******************************
		* Aspect oriented programming *
		*******************************
		
		 -->
		<dependency>
			<groupId>org.aspectj</groupId>
			<artifactId>aspectjweaver</artifactId>
		</dependency>

I get

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.3.RELEASE)

2019-03-31 21:08:10.332  INFO 10564 --- [           main] d.d.a.b.api.Application                  : Starting Application v0.0.1-SNAPSHOT on VAA2DAE009 with PID 10564 (D:\git\build-and-qa-manager-api_spring\target\build-and-qa-manager-api-0.0.1-SNAPSHOT.jar started by T08958A in D:\git\build-and-qa-manager-api_spring)
2019-03-31 21:08:10.341 DEBUG 10564 --- [           main] d.d.a.b.api.Application                  : Running with Spring Boot v2.1.3.RELEASE, Spring v5.1.5.RELEASE
2019-03-31 21:08:10.343  INFO 10564 --- [           main] d.d.a.b.api.Application                  : No active profile set, falling back to default profiles: default
2019-03-31 21:08:12.050  WARN 10564 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'mvcContentNegotiationManager' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.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.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=mvcContentNegotiationManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] for bean 'mvcContentNegotiationManager': There is already [Root bean: class [org.springframework.web.accept.ContentNegotiationManagerFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2019-03-31 21:08:12.068  INFO 10564 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-03-31 21:08:12.072 ERROR 10564 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'mvcContentNegotiationManager', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class], could not be registered. A bean with that name has already been defined in null and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

There should be not BeanDefinitionOverrideException with the starter from spring boot.

I tried to set following in application.properties:

logging.level.de.datev.alm.build_and_qa_manager.api = DEBUG
spring.main.allow-bean-definition-overriding = true

but I got same exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions