I'm running the following code in WildFly to create an EntityManagerFactory CDI bean for application deployments to use but I don't seem to be able to use the passed bean name ("pu1") in a test that has:
"
@Inject
@Named("pu1")
EntityManagerFactory entityManagerFactoryByPuName;
"
I expect that the following container code is naming the created bean but I thought the passed name would work with @Named but it doesn't seem to. The following EE container code (AfterBeanDiscovery callback) is doing the following which includes a call to "beanConfigurator.name(persistenceUnitMetadata.getPersistenceUnitName()):". Should setting the bean name this way allow @Named references to the passed name ("pu1" in this case) lookup the created bean as I am showing above?
"
private void entityManagerFactory(
AfterBeanDiscovery afterBeanDiscovery,
PersistenceUnitMetadata persistenceUnitMetadata,
List<String> qualifiers,
IntegrationWithCDIBag integrationWithCDIBag) throws InstantiationException, IllegalAccessException {
String scope = applicationScoped;
// EntityManagerFactory setup
BeanConfigurator<EntityManagerFactory> beanConfigurator = afterBeanDiscovery.addBean();
beanConfigurator.addTransitiveTypeClosure(EntityManagerFactory.class);
try {
if (!persistenceUnitMetadata.isDuplicate()) {
beanConfigurator.name(persistenceUnitMetadata.getPersistenceUnitName());