-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable isolation of config properties into a separate POJO #240
Comments
This isn't a new idea but it's good that you raised an issue for it because it's not being tracked right now. I agree something like this would be convenient. In fact, I already proposed it with a very old PR #42 - the There was also a discussion on the google group somewhere. I think the agreement was that we skipped it for config version 1.0 and reevaluate later. |
Hi @vsmid, welcome to the MicroProfile party! |
Thanks :-) Yeah, i did not see it, will look better next time. |
This makes even more sense if the suggested REST type-safe client is finalized: eclipse/microprofile-rest-client#12 Adding a type-safe access to config values proposed in this issue would be very similar to the REST type-safe client and would make MicroProfile API easier to use and compact. |
Sounds sensible. We also discussed this prefix for staging, e.g. test. or live. etc. This might be related but not the same. We can discuss on this week's hangout. |
Typesafe Config has an interesting approach to this, although annotations as suggested by @vsmid & @OndrejM would make it nicer: https://github.com/typesafehub/config#configbeanfactory |
+1 to have it asap. Only difference i see is to use interfaces instead of pojos since it should stay anemic. DeltaSpike has it and all apps I developed since a few years got a configuration consistency enhancement from it. Not sure it does worth waiting since technically it is easy and the gain immediate. |
@rmannibucau What do you mean that with interfaces it would by anemic? Interfaces make sense to me but an object would do the same job. In fact, with objects this functionality can be achieved already, except the common prefix:
So this functionality is just a sugar that saves some typing. In fact, we already specify that the name of the property is generated from the class name and the field name. If we specify that if
As a second step, we can make it work also with an interface:
But it's much more complicated to specify
I think the approach with just adding new annotation |
Issue with a pojo is you cant do much and actually just stay on the existing features whereas a proxy enables to:
Getters are then not needed at all and you just used methods, trivial model and efficient :) |
Big +1 to this proposal. In my experience with MP-Config it is very helpful to have all of the configurable settings in one central location so I don't need to grep my application for When I used MP-Config in one of my applications, once I got up to >5 config properties I naturally consolidated them all into a single class like this: |
I think the issue #334 created by @hwellmann deserves some attention. @ApplicationScoped
@Configuration(prefix = "com.example.myapp.client.")
public interface MyConfig {
@ConfigProperty(name = "url")
String url();
@ConfigProperty(name = "timeout", defaultValue = "30000")
long timeout();
} As a first step, a simpler approach might be possible public interface MyConfig {
@ConfigProperty(name = "com.example.myapp.client.url")
String url();
@ConfigProperty(name = "com.example.myapp.client.timeout", defaultValue = "30000")
long timeout();
} This could enable us to be more flexible in the future. For example, you could define the paths as in JAX-RS @Path("root")
public class Resource {
@Path("sub")
...
} Not sure if @ConfigProperty(name = "com.example.myapp.client")
public interface MyConfig {
@ConfigProperty(name = "url")
String url();
@ConfigProperty(name = "timeout", defaultValue = "30000")
long timeout();
} is semantically correct, but being consistent in the API is a major factor to consider. |
+1, this is what we implemented in geronimo.
|
@radcortez would be worth doing a comparison of what's proposed here vs what was already done in Quarkus |
It is similar. It is actually very well documented in Quarkus: |
AFAIK quarkus didnt solve the isolation/bulk. Side note: geronimo config didnt merge the bean config mapper (as opposed to quarkus) to only keep interface support cause bean/class support is built in with cdi already. Surely something to consider, so just a global defaults+support is needed. |
Let's get this done in MP 2.0. |
The thing with interfaces is interesting. Class approach has some nice advantages, e.g. natural integration with serialization libraries. My opinion is that this feature should enable property value injection to any instance marked as viable by adding annotation with group prefix or something like that. This is currently possible but it produces unnecessary large amount of annotations. Something like this should be possible: user.name=John
user.address.street=Peckham Street @ConfigProps(prefix="user")
class UserData {
String name;
Address address;
...
}
class Address {
String street;
...
} |
The group annotation - note that it can be configproperty today and default value be a global json - is not a marker for this feature IMHO. The default prefix can be the qualified name of the type.
Hope it makes sense |
Serialization of these config groupings is a bit questionable. Are you serializing the configuration as it was on the source process, or are you serializing a handle to a grouping of configuration properties that reflects the current process configuration? What is the use case for either possible approach? |
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
Signed-off-by: Emily Jiang <[email protected]>
* 240 config properties Signed-off-by: Emily Jiang <[email protected]>
hi @Emily-Jiang, was this issue closed because it was implemented somewhere? Its not clear what the resolution is |
hi @Emily-Jiang , seems the solution is partial and only strictly equivalent to what is in 1.0 (add @Inject on all injections and it is 1-1 so this does not bring any new feature, just makes the API more verbose/complex):
|
@rmannibucau this issue is a kind of shortcut to 1.0 without bringing any new features. However, for the 2nd point, it might cope better as the endpoints will be resolved at the same time, so a best effort consistent set might be achieved. As for your first point, please go ahead to raise a separate issue, we can expand the ConfigProperties to do the mapping. |
Need to reopen this for further update based on some feedback and discussion on the google group mailinglist. |
Hi,
i think it would be a nice feature to add another annotation e.g.
@ConfigProperties
which would allow injecting a group of properties with the same prefix into a separate POJO. This would reduce the amount of@Inject
and@ConfigProperty
annotations and would allow better usage of the same set of properties across multiple classes.microprofile-config.properties:
Example class:
Referencing PersonData:
The text was updated successfully, but these errors were encountered: