Resource Injection

Components can obtain references to system services us as DataSources, the TransactionManager, and the kernel work scheduler using resource injection. A resource is injected using the @Resource annotation. The annotation takes an optional name attribute, which corresponds to the system service name. For example, the following injects the runtime TransactionManager:

public void TheComponent ....{

   @Resource(name="TransactionManager")

   protected TransactionManager tm;

    //...

}

The name can also be omitted:

public void TheComponent ....{

   @Resource
   protected TransactionManager tm;

   //...

In this case, the resource name will be inferred from the resource class name.

DataSource injection

One of the most common uses of resource injection is to obtain references to configured DataSources. In this case, the resource name corresponds to the name of the configured datasource:

public void TheComponent ....{

   @Resource(name="ds1")
   protected DataSource ds;

   //...

ExecutorService Injection

Another common resource injection case is obtaining a reference to the kernel work scheduler to submit work for asynchronous execution:

public void TheComponent ....{

   @Resource
   protected ExecutorService service;

   //...