[
https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin...
]
Matěj Novotný commented on WFLY-11956:
--------------------------------------
I took a glance at this (as a CDI guy, with resteasy and validator and I am greenhorn so
mind that please).
Looking at what jaxrs does, there is a wrapper for CDI's {{InjectionTarget}} -
that's the {{JaxrsInjectionTarget}} Brian mentioned earlier.
Behind the scenes, it enriches the invocation of {{inject()}} that CDI performs with jaxrs
property injection and finally with validation.
Since {{InjectionTarget}} also has {{postConstruct()}} method, the validation could
theoretically be moved there - I did a dirty check with this and it worked for me (for the
test application). Notably this works even if the class itself does not use any
{{@PostConstruct}}, the method on {{InjectionTarget}} will be invoked all the same. Not a
clue what else it can possibly break though ;-)
Nonetheless, none of the above explains why hibernate validator calls the method *twice*
which it IMO shouldn't.
It does so from [these two subsequent
lines|https://github.com/hibernate/hibernate-validator/blob/6.0.15.Final/...]
- the if check and the following line both end up with a reflective method invocation. I
suppose this could be done once and the result stored if it's needed for several
separate validations?
@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: Alessio Soldano
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)