-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Description
The desired steps to a valid Formatters registration are:
- First of all, the method addWebMvcConfigurers located in WebMvcConfigurationComposite should registrate all the web configurers. That includes the
formatters. - After that, when some component needs to
@AutowiredaConversionServiceinstance, the method mvcConversionService located in WebMvcConfigurationSupport obtains aConversionServiceinstance and register all the existingformatterson it before return the instance.
However, if a @Configuration class extends the WebSecurityConfigurerAdapter abstract class, some component is trying to @Autowired a ConversionService instance before the formatters have been registered in the Spring context, so the addFormatters method doesn't include any formatters on it.
I've just created the following proof of concept that uses Spring Boot to reproduce this issue:
https://github.com/jcagarcia/proofs/tree/master/spring-security-and-formatters
If you execute this proof of concept using the mvn compile spring-boot:run command, you could check that the Create Pets view shows an enum value without apply the conversion to String.
Seems like the component that requires the ConversionService instance is the ContentNegotiation that is beeing @Autowired in the WebSecurityConfigurerAdapter.
A simple work-around is to @Override the setContentNegotiationStrategy method in our SecurityConfiguration class without include the @Autowired annotation. (The proof of concept includes this work-around commented)
After that, execute this proof of concept again using the mvn compile spring-boot:run command and you could check that the Create Pets view shows an enum value with a valid format applied.
I think this is not the best solution because the ContentNegotiationStrategy is not beeing @Autowired anymore.
I've just created a question in StackOverflow to obtain some answer:
Best Regards,

