-
1. Re: JpaInjectionServices implementation is created three times?
manovotn Feb 6, 2019 10:05 AM (in response to ljnelson)Hi Laird
I haven't really gone into code, but just looking at the javadoc you posted, it says -
JpaInjectionServices
is a per-module service.So I would suppose your application has multiple modules and each of them loads it separately?
-
2. Re: JpaInjectionServices implementation is created three times?
ljnelson Feb 6, 2019 1:29 PM (in response to manovotn)Thanks for your time. I bet that's it. I think I have more than three modules, but I can't swear to that, so I'll look there first. Actually, see my next reply.
-
3. Re: JpaInjectionServices implementation is created three times?
ljnelson Feb 6, 2019 2:06 PM (in response to ljnelson)Actually, let me check that. If I'm writing a CDI SE application consisting of several jar files with
META-INF/beans.xml
resources in them all on one classpath I should just have one big module, yes? The javadocs forDeployment
say:For an application deployed in the SE environment, all library jars and classpath directories should be searched, and the bean deployment archive structure built. A single, logical deployment archive will be built for all beans and beans.xml files found on the classpath.
After debugging, I can see that there is:
- one
Deployment
with - six
BeanDeploymentArchive
s
This results in three
ResourceLoader
s that are used to find additional services.Each
ResourceLoader
finds myJpaInjectionServices
class.I don't see a correlation between number of modules and instances of my
JpaInjectionServices
class.It looks like for a CDI SE application, you will always end up with at least three
ResourceLoader
s used bygetAdditionalServices()
:- one is the
ClassLoaderResourceLoader
used by the encompassingDeployment
; it gets added to everyBeanDeploymentArchive
- two is the
WeldClassLoaderResourceLoader.INSTANCE
added always to the set ofResourceLoader
s used bygetAdditionalServices()
- three is the
DefaultResourceLoader.INSTANCE
added always to the set ofResourceLoader
s used bygetAdditionalServices()
Each
ResourceLoader
will instantiate eachService
it finds. In my case, myJpaInjectionServices
is instantiated three times. Then when it is placed into theServiceRegistry
, only the first instance is kept and the remaining two are discarded, becauseshouldOverride()
returnsfalse
(as it always will in this case).So this has nothing to do with number of modules or archives, and in fact every
Service
implementation will be created three times in a CDI SE application. That seems wrong, but I don't see an immediately obvious way to fix this. - one