[jboss-jira] [JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
Christian Zambrano (Jira)
issues at jboss.org
Thu Apr 25 14:05:00 EDT 2019
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13726806#comment-13726806 ]
Christian Zambrano commented on WFLY-11956:
-------------------------------------------
[~ron_sigal] [~gunnar.morling] To help other people(or myself) following the case here is the section of the spec quoted:
JAX-RS implementations SHOULD use the following process to validate resource class instances after theyhave been instantiated:
Phase 1 - Inject field values and initialize bean properties as described in Section 3.2.
Phase 2 - Validate annotations on fields, property getters (if enabled) and the resource class. The order inwhich these validations are executed is implementation dependent.
Phase 3 - Validate annotations on parameters passed to the resource method matched.
Phase 4 - If no constraint violations found thus far, invoke resource method and validate returned value
I don't think the spec forbids an implementation to perform phase 2 after the call to PostConstruct, so you are correct the current implementation is not wrong but I think it is hard to argue that it has undesirable side effects. Calling the PostConstruct before Phase 2 would still be in compliance with the spec and would better fit the sequence of events that are expected from CDI which is for the PostConstruct to be called after injections.
> @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
> ----------------------------------------------------------------------------------------------------------
>
> Key: WFLY-11956
> URL: https://issues.jboss.org/browse/WFLY-11956
> Project: WildFly
> Issue Type: Bug
> Components: Bean Validation, REST
> Affects Versions: 16.0.0.Final
> Reporter: Joerg Baesner
> Assignee: Ronald Sigal
> Priority: Major
> Attachments: logging.txt, playground.zip
>
>
> Having a bean class with {{@ApplicationScoped}}, which has a {{@PostConstruct}} and is implementing the following _Interface_:
> {code}
> @Path("/validated")
> public interface ValidatedJaxRsInterface {
>
> @GET
> @Valid
> @Produces(MediaType.APPLICATION_JSON)
> GreetingModel getHelloGreeting();
> }
> {code}
> will result in calling the {{getHelloGreeting}} method of the implementation class twice *_before_* the {{@PostConstruct}} is getting executed.
> This can be reproduced with the attached reproducer application...
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
More information about the jboss-jira
mailing list