简体   繁体   中英

How should I externalize configuration for a jar in a tomcat webapp?

I'm working on a small project for my company for converting currency. The plan is to provide a jar file with a minimal interface to keep things simple for my coworkers. The problem I'm running into is determining the best way to provide configuration for the jar.

See the jar needs to know some information that I don't want the client code to necessarily need to worry about, specifically the location of the web service that is being consumed.

Here is the interface for context, but please don't get too distracted critiqing it :)

public static ConversionResult convert(String amount, 
    String currencyCodeFrom, String currencyCodeTo);

The user will get the jar during the maven build and then used within tomcat webapp. Then they will need to setup configuration somehow, and I'm having a hard time deciding which route to take.

Here are the options I'm considering:

  • Setup JNDI in Tomcat
  • Resource bundles
  • Spring PropertyOverrideConfigurer
  • Something custom

Given this setup, what is the best way to do this? Is there a better option that I'm missing?

You have given good options. One more would be Dependency Injection . Guice is a good framework for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM