...
There are several possible ways to refer to it, as follows.
Injected Name Match
The BY matching variable name actually matches the configured name of the resource.to resource name
Code Block | ||||
---|---|---|---|---|
| ||||
@Stateless public class FooBean { @Resource DataSource myDerbyDatabase; } |
Name Attribute Match
The name attribute of the @Resource annotation matches the configured name of the resource.OR BY matching name
Code Block | ||||
---|---|---|---|---|
| ||||
@Stateless public class FooBean { @Resource(name="myDerbyDatabase") DataSource dataSource; } |
JNDI ENC Injection
We inject the resource into the JNDI environment using the name attribute of the @Resource to match the configured name of the resource.OR BY JNDI lookup
Code Block | ||||
---|---|---|---|---|
| ||||
@Resource(name="myDerbyDatabase", type="javax.sql.DataSource") @Stateless public class FooBean { public void setSessionContext(SessionContext sessionContext) { DataSource dataSource = (DataSource) sessionContext.lookup("myDerbyDatabase"); } public void someOtherMethod() throws Exception { InitialContext initialContext = new InitialContext(); DataSource dataSource = (DataSource) initialContext.lookup("java:comp/env/myDerbyDatabase"); } } |
...