[jboss-jira] [JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
Ronald Sigal (Jira)
issues at jboss.org
Wed Apr 24 12:59:00 EDT 2019
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13726234#comment-13726234 ]
Ronald Sigal commented on WFLY-11956:
-------------------------------------
re: "t kind of makes sense to call this every time and within this method you figure whether you actually have some of those methods, or make it no-op otherwise. Cannot guarantee that other impls don't handle it differently though."
Well, yes, [~christian.zambrano], but the CDI implementation could check if there is a @PostConstruct annotated method and, if not, skip calling postConstruct(). It seems safer to not assume that postConstruct() will be called.
re: "whether all of the required calls can be done in a PostConstruct is hard to know"
The javadoc for @PostConstruct says, "The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization." It sounds like it's saying that in a *properly defined* class, all initialization would be completed after a call to a @PostConstruct annotated method, at which point it would be safe to do validation. If a class doesn't adhere to that, then it's out of our hands.
re: "I was simply trying to agree that if having a validation.xml with the contents you provided would have turned off this behavior that would have been the best answer for an app-developer to control this behavior. "
Ah, good. I wish I understood why I'm not getting the behavior I expect. [~guillaume.smet], can you explain what I'm missing?
> @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