-
1. Re: @PostConstruct no longer called on stateless session bean usage
pferraro Nov 13, 2018 11:27 AM (in response to ahofle)These days, WildFly default configurations use instance pools for @Stateless EJBs, since this commit:
Switch default configs to use auto-configured strict-max-pools · wildfly/wildfly@02f2144 · GitHub
The EJB container triggers @PostConstruct methods only after new instances are created. When using @Stateless EJB instance pooling, each invocation will not created a new instance, but rather use an instance from the pool, thus you should not expect to see a @PostConstruct method triggered for each method invocation.
Refer to §4.7.1 of the EJB specification for details.
-
2. Re: @PostConstruct no longer called on stateless session bean usage
ahofle Nov 13, 2018 5:45 PM (in response to pferraro)Thank you for the reply, you are right...the older version was simply not pooling. Is there any way to disable the pooling (like the older behavior) or otherwise add some sort of handler when an EJB is taken from the pool and is about to be used to service a request? There is some security related initialization that we really need to perform once per service invocation.
-
3. Re: @PostConstruct no longer called on stateless session bean usage
pferraro Nov 13, 2018 6:03 PM (in response to ahofle)Rather than disabling instance pooling (which you would do by removing the strict-max-pool configuration from the stateless element within the ejb3 subsystem) which would impact performance and reduce the portability of your application, I would recommend you instead implement your security related initialization within AroundInvoke [1] callbacks.
See §7.3 of the EJB specification for details.