Description:
|
Weld SPI offer us the mechanism to bootstrap custom Service by overriding it is Deployment. In a Weld SE environment, we would do the following to bootstrap a custom TransactionService:
{code:java}
weld = new Weld(){ @Override protected Deployment createDeployment(ResourceLoader resourceLoader, Bootstrap bootstrap) { Deployment deployment = super.createDeployment(resourceLoader, bootstrap); deployment.getServices().add(TransactionServices.class, new InMemoryTransactionServices()); return deployment; } };
{code}
Though, when using third parties libraries like Arquillian to bootstrap Weld, it is fairly complicated to override the Weld Deployment.
By looking at the Weld 2.0.3.Final source code, especially the WeldBootstrap class, it would be nice if code would lookup for a well known service or system property to init the services.
ex, instead of:
{code:java}
if (!registry.contains(TransactionServices.class)) { log.info(JTA_UNAVAILABLE); }
{code}
we could do something like:
{code:java}
if (!registry.contains(TransactionServices.class)) { // first, lookup for a system property TransactionServices transactionServices = System.getProperty("org.jboss.weld.transaction.spi.TransactionServices"); if (transactionServices != null){ registry.getServices().add(TransactionServices.class, transactionServices); } // else, lookup for a service else if (ServiceLoader.load(TransactionServices.class).hasNext()) { transactionServices = ServiceLoader.load(TransactionServices.class).next(); registry.getServices().add(TransactionServices.class, transactionServices); } // then we can safely assume that TransactionServices is really unavailable else { log.info(JTA_UNAVAILABLE); } }
{code}
By doing so, it would resolve my issue documented in the related forum references.
Thanks,
|