-
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 -
JpaInjectionServicesis 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.xmlresources in them all on one classpath I should just have one big module, yes? The javadocs forDeploymentsay: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
Deploymentwith - six
BeanDeploymentArchives
This results in three
ResourceLoaders that are used to find additional services.Each
ResourceLoaderfinds myJpaInjectionServicesclass.I don't see a correlation between number of modules and instances of my
JpaInjectionServicesclass.It looks like for a CDI SE application, you will always end up with at least three
ResourceLoaders used bygetAdditionalServices():- one is the
ClassLoaderResourceLoaderused by the encompassingDeployment; it gets added to everyBeanDeploymentArchive - two is the
WeldClassLoaderResourceLoader.INSTANCEadded always to the set ofResourceLoaders used bygetAdditionalServices() - three is the
DefaultResourceLoader.INSTANCEadded always to the set ofResourceLoaders used bygetAdditionalServices()
Each
ResourceLoaderwill instantiate eachServiceit finds. In my case, myJpaInjectionServicesis 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
Serviceimplementation 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