Comments (3)
Duplicate keys are not supported by properties files. This means that they would be invalid Java properties files.
Multiline values are supported by properties files out of the box. Example:
you can do something like this:
config.prop=Sometext,\
OtherText,\
...
The above will work just fine as:
@Key("config.prop");
public String configProp();
Another option is to use XML. It will be released in the next version. See XML Support :
<config>
<prop>
Sometext
OtherText
...
</prop>
</config>
Then, for the above xml you can define the newline as separator, or define a SeparatorClass.
@Separator("\n") //newline
@Key("config.prop");
public String configProp();
Indexed properties are an option to map legacy configuration files, that are using this notation. Which is quite wrong from my point of view, since properties files do support multiline values out of the box, plus owner adds support for
collections, so the best way to implement this is the first example in this comment, unless there is some good reason I am missing.
Adding indexed properties adds some overhead on properties lookup since we need then to check for multivalues every time a property is requested, then since they are indexed we also need to sort them and return in the proper order, plus... what would be the correct behavior if one index is missing? example:
server.0=...
server.1=...
server.3=... # server.2 is missing!
server.4=...
So, I will consider this feature for future development if I get some good understanding what problem the indexed properties are solving that isn't already solved by multiline properties values (supported by default in Java properties files) and owner collections support.
from owner.
Do you support this type of XML structure, I want get elements by value.
env.name this the key for each of my servers.
<servers>
<env>
<name>DEV</name>
<hostname>locahost1</hostname>
<port>60000</port>
<user>myuser1</user>
<password>mypass1</password>
</env>
<env>
<name>SIT</name>
<hostname>locahost2</hostname>
<port>60010</port>
<user>myuser2</user>
<password>mypass2</password>
</env>
<env>
<name>UAT</name>
<hostname>locahost3</hostname>
<port>60020</port>
<user>myuser3</user>
<password>mypass3</password>
</env>
<env>
<name>SVP</name>
<hostname>locahost4</hostname>
<port>60030</port>
<user>myuser4</user>
<password>mypass4</password>
</env>
</servers>
from owner.
@Ronmck: No, your xml can't be supported at the moment. You can change it a follows:
<servers>
<dev>
<name>DEV</name>
<hostname>locahost1</hostname>
<port>60000</port>
<user>myuser1</user>
<password>mypass1</password>
</dev>
<sit>
<name>SIT</name>
<hostname>locahost2</hostname>
<port>60010</port>
<user>myuser2</user>
<password>mypass2</password>
</sit>
<uat>
<name>UAT</name>
<hostname>locahost3</hostname>
<port>60020</port>
<user>myuser3</user>
<password>mypass3</password>
</uat>
<svp>
<name>SVP</name>
<hostname>locahost4</hostname>
<port>60030</port>
<user>myuser4</user>
<password>mypass4</password>
</svp>
</servers>
This one should work fine.
I want to modify OWNER to support something like this:
interface MyConfig extends Config {
@Key("servers.${env}.name");
String name();
@Key("servers.${env}.hostname");
String hostname();
@Key("servers.${env}.port");
Integer port();
}
ConfigFactory.setProperty("env", "dev");
MyConfig cfg = ConfigFactory.create(MyConfig.class);
This way you can select ${env}
in the ConfigFactory (or from the system properties) and have the above interface map to the appropriate section.
This is not working at the moment, but it is easy to implement and it will be available in the next release.
from owner.
Related Issues (20)
- Does this lib support profile ? HOT 2
- Convert environment variables to properties support HOT 4
- The annotation @Config.Key is disallowed for this location
- Distinct between actual source of a merged property
- System properties aren't actually checked for changes in reload logic
- Multiple keys HOT 3
- Owner Properties File Location HOT 1
- Unable to ThreadLocal ConfigCache.getOrCreate()
- Accessible.fill() does not decrypt @EncryptedValue properties
- Initializing maps HOT 1
- Converter / Decryptor is not being called when property value is referenced in another property
- Get wrong value which contains '%' HOT 1
- Tests about Reloading failing seemingly randomly
- Fix Vulnerable JUnit - Upgrade JUnit version
- Dependency Dashboard
- System property is @Sources - how to provide a default value? HOT 1
- java.lang.IllegalAccessException when using OWNER with Java 17 HOT 1
- Is it possible, somehow, to have Variables expansion with Accessible.getProperty(String) HOT 1
- Confusing documentation for ByteSizeConverter HOT 1
- Incompatibility between @Spy annotation and java.util.Properties in OpenJDK17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from owner.