[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
Wed Apr 24 08:59:00 EDT 2019
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13726075#comment-13726075 ]
Christian Zambrano commented on WFLY-11956:
-------------------------------------------
> Christian Zambrano, I don't understand. My understanding is that postConstruct() would be called after all CDI injections are performed. Calling the @PostConstruct annotated method would be the last chance to perform additional initialization, so doing the verification after that would seem to be OK. What am I missing?
A class can impose a contract where a series of methods calls may have to take place on an object before a given method should be called, whether all of the required calls can be done in a PostConstruct is hard to know. Can't really come up with a real-life example. Having a method be called **outside** when it is attempted to be accessed by a client is just plain unexpected. After taking a look at the Bean Validation spec it looks like methods that comply with the JavaBean naming convention are expected to be called to validate an object so having these methods be called after the @PostConstruct is called is as good as it can get and it would solve our **current** problem
> Christian Zambrano, sorry, which behavior are you referring to?
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.
> @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