2 Replies Latest reply on Dec 29, 2018 5:51 AM by simix

    Dynamic datasource name and resource-ref to it

    simix

      Hello.

      I need to specify datasource JNDI name dynamically for my enterprise application.

      Can i add this datasource to resource-ref dependency ? Name of datasource  is unknown previously.

      I need resource-ref because it is control shutdown order (datasource after my application).

        • 1. Re: Dynamic datasource name and resource-ref to it
          claudio4j

          You can use a variable name on your persistence.xml or web.xml, an example

           

          <jta-data-source>${ks.ds}</jta-data-source>

           

          For this to work you need

          1) in the EE subsystem (Web Console -> Configuration -> EE), change the "Spec Descriptor Property Replacement" to true

          2) set the property/value in the Properties view (Configuration -> System Properties)

          1 of 1 people found this helpful
          • 2. Re: Dynamic datasource name and resource-ref to it
            simix

            So, while I try this recommendation, I have found more fit method for my case - using default datasource binding on the page EE -> default bindigs. Is it JavaEE compliant (specify JNDI of default datasource in container) ?

            Datasource will inject with code

             

            @Resource

            private DataSource myDatasource

             

            and shutdown order is safe

             

            Thank you