Description
Spring Boot Version: 1.5.13.RELEASE
Setup
ApplicationContext with a Bean declared with an autowire dependency to HttpServletRequest
(the used ApplicationContext is a little bit more complex).
Problem
For a non embedded environment (Tomcat deployment) the application context boots successfully. For an embedded environment, the application context fails to start with the exception:
....NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.http.HttpServletRequest' available: expected at least 1 bean which qualifies as autowire candidate.
Reason
The HttpServletRequest
substitution is performed by an ObjectFactory
registered by org.springframework.web.context.support.WebApplicationContextUtils.registerWebApplicationScopes(...)
. The registerWebApplicationScopes(...)
call is performed by EmbeddedWebApplicationContext.selfInitialize(...)
. For an embedded environment the method EmbeddedWebApplicationContext.createEmbeddedServletContainer()
is invoked previous to the initializer which causes Eager Bean creation of the ApplicationContext.
Expected
HttpServletRequest
is resolved, no matter if it is an embedded or non embedded environment.