I don't understand @Resource mappedName element at all

爷,独闯天下 提交于 2019-12-04 10:24:52

Say you have a connection pool (javax.sql.DataSource) configured in the application server and placed in JNDI under e.g. java:datasources/jta/MyDb.

Say a component (an EJB probably) of your application needs to access a database. The DataSource could be injected as:

@Resource
private DataSource theDatabase;

Your component may be generic, i.e. can be deployed in multiple environments. Or in a single environment there may be many datasources (java:datasources/jta/MyDb1, java:datasources/jta/MyDb2, ...). How do you map the specific DataSource to your component?

@Resource(mappedName="java:datasources/jta/MyDb")
private DataSource theDatabase;

(Exact details could be missing or be application-server specific, but I hope you get the general point.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!