문제

Java 라이브러리에서 하드 코딩 된 모든 값을 제거하는 중이며 런타임 구성을 처리하는 데 가장 적합한 프레임 워크 (0 또는 0에 가까운 구성)가 무엇인지 궁금합니다.XML 기반 구성 파일을 선호하지만 필수는 아닙니다.

프레임 워크에 대한 실제 경험이있는 경우에만 답장 해주세요.예를 찾는 것이 아니라 경험 ...

도움이 되었습니까?

해결책

하드 코딩 된 값이 단순한 키-값 쌍인 경우 java.util.Properties .xml보다 훨씬 간단하고 사용하기 쉬우 며 구현하기가 매우 간단합니다.

Java로 작업 중이고 디스크에서 저장하거나 검색하는 데이터가 키 값 쌍 (귀하의 경우처럼 들림)으로 모델링 된 경우 더 나은 솔루션을 상상할 수 없습니다.

나는 더 큰 프로젝트에서 작은 패키지의 간단한 구성에 속성 파일을 사용하고 전체 프로젝트에 대한 더 글로벌 구성으로 사용해 왔으며 문제가 없었습니다.

물론 타사 라이브러리를 사용하지 않아도된다는 큰 이점이 있습니다.

다른 팁

Apache Commons 구성 이 훌륭하게 작동합니다.속성, XML, JNDI 등을 포함하여 백엔드에서 다양한 형식으로 구성을 저장할 수 있도록 지원합니다.사용 및 확장이 쉽습니다.최대한의 유연성을 얻으려면 팩토리 를 사용하여 구성을 가져오고 구성 인터페이스 이후

직선 속성 파일과 구별되는 Commons Configuration의 두 가지 기능은 공통 유형 (int, float, String 배열)으로의 자동 변환을 지원하고 속성 대체를 지원한다는 것입니다. 라코 디스

다음은 다양한 옵션입니다.

공통 구성

우리는 이것을 사용하고 있습니다.속성 파일만으로는 훨씬 쉽게 처리 할 수 있지만 더 복잡한 데이터 공용 구성을 나타내야하는 경우이 작업을 수행하고 속성 파일도 읽을 수 있습니다.

복잡한 일을하지 않는다면 나는 속성 파일을 고수 할 것입니다.

고급 (및 typesafe) 작업을 수행하려면 다음을 참조하십시오. http://www.ibm.com/developerworks/java/library/j-configint/index.html

the Intelligent Parameter Utilization Tool (InPUT, page) allows to externalize almost any (hard coded) decision as a parameter into an XML based configuration file. It has been initiated in early 2012 as a response to the perceived deficiencies in existing configuration tools with respect to generality, and separation of concerns.

InPUT is probably more powerful than most use cases require, as it allows for the programming language independent formulation of experimental data (input - output), with features such as the definition of complex descriptor to class mappings, or randomized configuration spawning and validation based on predefined value ranges (for test and research, e.g. Monte Carlo simulations). You can define parameters with sub parameters, relative restrictions on parameter values (numerical param a > param b) etc. .

Its still in beta, but rather stable, I use it for my research, for the configuration and documentation of experiments, and for teaching purposes. Once it is available for other languages (C++ adapter in the pipe), other researchers/practitioners can reuse the descriptors running their implementations of the same algorithms in C++ (using the code mapping concept). That way, experimental results can be validated/programs can be migrated more easily. The documentation is still in working process, but a couple of examples are available on the page. InPUT is open source software.

For those interested, the Conceptual Research Paper.

I tend to use java.util.Properties (or similar classes in other languages and frameworks) wrapped in an application-specific configuration class most of the time, but I am very interested in alternatives or variations on this. Especially since things can become a bit tricky if graphical configuration dialogs or multiple views on the configuration data is involved.

Unfortunately I don't have any experience with specific libraries for Java (except with the ones I have written myself), but any pointers would be appreciated.

Update

OK. That wasn't entirely true, three is the Spring Java Configuration Project.

I wrote about this a couple of weeks ago and came to the conclusion that XML is one of the most widely used notations.

Is it the best? I don't think so, I really like JSON, but the tooling is still not up to XML so I guess we have to wait and see.

You can try YamlBeans. This way you write whatever classes you want to hold your config data, then you can automatically write and read them to and from YAML.

YAML is a human readable data format. It has more expressive power than java.util.Properties. You can have lists, maps, anchors, typed data, etc.

Please take a look at this URL: http://issues.apache.org/jira/browse/CONFIGURATION-394

The Configuration framework which we're looking for it is something on top of Apache Commons Configuration and must support Concurrency Issues, JMX issues and most of stores(e.g .properties file, .xml files or PreferencesAPI).

What weblogic team provides on 'Administration Console' is intersting which through it you can have transactional(atomic) updates on configurations so that are registered listeners be notified.

The Apache guys insist that this project is out of scopes of Commons Configuration, maybe!

I've attached a simple configuration framework, take look please.

I just posted a brief bit of code about using Spring's ClassPathResource as an alternative to IoC. ClassPathResource permits you to place property files anywhere on the classpath (e.g., all in one place, or as peers to the code they configure. My example just uses java.util.Properties, so you can use the plaintext "name=value" style or its XML format.

Properties files a very simple, if you need something more functional, you could format some of your configuration files as Java classes. These can be placed in a different package/module and can be pre-compiled or loaded at runtime with a library like BeanShell.

Note: In the simplest case (pre-compiled) you don't need any additional libraries.

Regarding the suggestions to use java.util.Properties - starting in jdk 1.5, the Preferences API (java.util.prefs) appears to be the preferred alternative to using the Properties API.

Reasons: increased scalability, back-end neutrality, ect.

You could have a look at newly announced tools4j-config whose mission statement is to allow you to easily handle configuration at runtime.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top