[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
Tue Apr 23 09:40:02 EDT 2019
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13725468#comment-13725468 ]
Christian Zambrano commented on WFLY-11956:
-------------------------------------------
> 1. As Christian has verified, it seems that getHelloGreeting() is getting called because A) it is a getter, and B) @Valid says that the returned GreetingModel should be validated, which means that getHelloGreeting() must be called.
[~ron_sigal] I know you just explained this to Martin above but I still don't get it. Here is how I am interpreting what you are saying, The Valid annotation is on a method, which means it should be triggered on method invocation, but because it is on a method that starts with 'get'(JavaBeans standard), the Valid annotation seems to be interpreted as requesting field-level validation which results on the call to getHelloGreeting be called right after a object of the class that implements the interface ValidatedJaxRsInterface is instantiated to answer the rest call instead of waiting for the method to be called for the first time. Did I get that right?
Your proposal of delaying the behavior described above until the PostConstruct is called, while better it can still lead to problems as the postConstruct may not have initialized everything is needed for the method to be called so having a way to turn this behavior off would be ideal for these cases.
> @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