External Configuration With JBoss

(2009年01月13日)发表于dzone.com: latest front page
In a project I’m currently working on, I need to make some parameters configurable, and they need to be outside the .war file that I’m deploying. For example, let’s say I’m creating a service which reads data from some other RESTful service. And let’s say that the other RESTful service has two URLs, one for test and one for production. I’d like to be able to deploy my .war, and then edit a file outside of that .war file to configure which URL my service should be using.
阅读全文...
本站相关内容:

Should that external configuration be XML?

Crazy Bob Lee, the proud father of Guice, likes programmatic interfaces for configuration. He commented on my blog entry "Annotations plus XML = Good Thing?":

You're asking the wrong question. We need external configuration. The question is, should that external configuration be XML? I don't think so.

He much prefers the following code which will instantiate a MyService object which internally has configuration @Annotations that allow Guice to appropriate create and inject dependencies:

  binder.bind(Service.class).to(MyService.class);
  bindConstant().annotatedWith(ServiceTimeoutConstant.class).to(5);

over spring's XML version:

<bean name="myService" class="com.some.package.MyService" >
  <property name="dao" ref="myDao" />
  <property name="serviceTimeout" value="5" />
</bean>

The important thing (as far as this blog entry is concerned) to note is that Bob prefers a programmatic approach not only for application construction purposes (meaning, asking the IoC Engine to create a MyService instance that will be used anywhere the Service.class interface is used for injection purposes). More importantly, and perhaps more controversially, he prefers using a programmatic approach for environmental configuration as well. I'm sure that he'd advocate using property files and JNDI when really necessary, but still use the bind/bindConstant methods to get the environmental dependencies into your application.

I showed the programmatic approach to some of my co-workers. Overall, it just didn't sit with them. Reactions ranged from "I'd have to see it in action before I feel comfortable with it" to "that's goofy." Perhaps we as a development group have come to accept XML as part of development. I'm going to stick with XML at my day job for now... especially since I'm stuck with JDK 1.4 and I can't use Annotations.

Should external configuration be XML?

New York Java Consultant

Crazy Bob Lee, the proud father of Guice, likes programmatic interfaces for configuration. He commented on my blog entry "Annotations plus XML = Good Thing?":

You're asking the wrong question. We need external configuration. The question is, should that external configuration be XML? I don't think so.

He much prefers the following code which will instantiate a MyService object which internally has configuration @Annotations that allow Guice to appropriate create and inject dependencies:

  binder.bind(Service.class).to(MyService.class);
  bindConstant().annotatedWith(ServiceTimeoutConstant.class).to(5);

over spring's XML version:

<bean name="myService" class="com.some.package.MyService" >
  <property name="dao" ref="myDao" />
  <property name="serviceTimeout" value="5" />
</bean>

The important thing (as far as this blog entry is concerned) to note is that Bob prefers a programmatic approach not only for application construction purposes (meaning, asking the IoC Engine to create a MyService instance that will be used anywhere the Service.class interface is used for injection purposes). More importantly, and perhaps more controversially, he prefers using a programmatic approach for environmental configuration as well. I'm sure that he'd advocate using property files and JNDI when really necessary, but still use the bind/bindConstant methods to get the environmental dependencies into your application.

I showed the programmatic approach to some of my co-workers. Overall, it just didn't sit with them. Reactions ranged from "I'd have to see it in action before I feel comfortable with it" to "that's goofy." Perhaps we as a development group have come to accept XML as part of development. I'm stuck with XML at my day job for now...

External Configuration with JBoss

mike desjardins (25 reads)

In a project I’m currently working on, I need to make some parameters configurable, and they need to be outside the .war file that I’m deploying. For example, let’s say I’m creating a service which reads data from some other RESTful service. And let’s say that the other RESTful service has two URLs, [...]

External Configuration With JBoss

In a project I’m currently working on, I need to make some parameters configurable, and they need to be outside the .war file that I’m deploying. For example, let’s say I’m creating a service which reads data from some other RESTful service. And let’s say that the other RESTful service has two URLs, one for test and one for production. I’d like to be able to deploy my .war, and then...

互联网相关内容:
Should that external configuration be XML? (2007年11月05日)
Should external configuration be XML? (2007年11月05日)
External Configuration with JBoss (2009年01月10日)
External Configuration With JBoss (2009年01月12日)
Maven - External Resources on Maven (2007年09月27日)
Great External Articles/Blogs. (2007年10月09日)
hibernate.org - External articles & tutorials (2007年10月25日)