开发者

How to do Application specific Configuration for a Framework

开发者 https://www.devze.com 2023-02-17 23:23 出处:网络
i want to write a Java EE framework for a generic type of applications. I\'m looking for a w开发者_Python百科ay to handle application specific config values in my framework.

i want to write a Java EE framework for a generic type of applications. I'm looking for a w开发者_Python百科ay to handle application specific config values in my framework.

To give an example: A component supplies a stateless session bean that handles persistence and i want to configure the name of the datasource that is used in a config file in my application (for example in the web-inf folder of the applications ear).

Now i have X>1 Applications that want to configure X different datasources for their specific persistence management.

Can anybody give me an example how to do that?

Greetings, Alexander


You should use the JNDI provider thats bundled with the application container. One of its purposes it to access resources, data sources in your case, in a highly dynamic fashion.

For JBoss, setting up a data source involves the following steps:

  1. deploy a *-ds.xml configuration file to the JBoss server's deploy directory. This defines the global JNDI name of the resources. There should be plenty of examples for a lot of databases available on the internet.
  2. add a resource-ref to the jboss-web.xml of any WAR or to the jboss.xml of any EJB jar for any bean that needs the resource. This defines the global JNDI name to local/component JNDI name mapping.
  3. add a resource-ref using the local JNDI name to the web.xml of any WAR or to the ejb-jar.xml of any EJB jar for any bean that needs the resource.

Once those things are in place, you can perform JNDI lookups to access the configured resource.

You can do these things to configure multiple data sources in JBoss and then make one or more of these data sources available to the web applications and EJBs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号