Skip to content
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

Spring Boot properties extension #6269

Merged
merged 1 commit into from
Dec 24, 2019

Conversation

gytis
Copy link

@gytis gytis commented Dec 19, 2019

cc @geoand

@geoand
Copy link
Contributor

geoand commented Dec 19, 2019

I hope to be able to review this tomorrow but I can't promise :)

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one very minor comment.

"artifact-id": "quarkus-spring-boot-properties",
"version": "999-SNAPSHOT",
"description": "Use Spring Boot properties annotations to configure our application"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I'll remove it. I saw other spring modules mentioned in this file so I followed the trend.

@geoand
Copy link
Contributor

geoand commented Dec 19, 2019

@gytis did you check why CI is failing?

@gytis
Copy link
Author

gytis commented Dec 20, 2019

@gytis did you check why CI is failing?

I think it failed because of fakeextensions.json. I've removed it so let's see if it will pass now.

@@ -35,17 +26,26 @@

public class ConfigPropertiesBuildStep {

@BuildStep
void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really minor complaint, but the rest of the class doesn't use lambda's so can we keep it consistent please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK will do. But I still think that streams are more readable :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to think the same :). Let's keep the streams in the other uses since those are for new classes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used to? What changed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disillusionment :). I liked them because they were cool, then once I stepped back from them for a while I started disliking them and find that I need to think more about what they are doing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of agree with simple cases, like the one in this method. Both stream and loop are easy to read in this case. But if it would be a method with a bunch of it/else and loops, I don't think it would more readable than stream with lambdas.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you there

return new ConfigPropertiesMetadataBuildItem(getReturnClassInfo(index, annotation), getPrefix(annotation));
}

private ClassInfo getReturnClassInfo(IndexView index, AnnotationInstance annotation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just inline this method since it's only called at one spot and more importantly it can only work when the target is a method

public class InterfacePropertiesResource {

@Inject
private InterfaceProperties properties;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop private from here (and the other instances in the integration test application)? The reason is that quarkus logs a warning for injections into private fields and we could use the cleanest test output we can get.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that. Why is package-private preferred to private?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Quarkus then doesn't need to use reflection to set the field. You can read more details here: https://quarkus.io/guides/cdi-reference#native-executables-and-private-members

</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary because quarkus-arc-deployment brings it in

@@ -0,0 +1,12 @@
### Current differences with Spring Boot properties.

1. Default values assigned with `=` operator are not supported.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is true?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, this readme wasn't supposed to be in this PR and is not fully correct. I'll remove it. = operator works for Spring Boot properties

### Current differences with Spring Boot properties.

1. Default values assigned with `=` operator are not supported.
2. Getters and setters are needed for all fields, including nested classes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I tried the Spring Boot way where a config field of a pojo type has only a getter and I ended up getting Quarkus extension that the field doesn't have a setter


1. Default values assigned with `=` operator are not supported.
2. Getters and setters are needed for all fields, including nested classes.
3. `@Bean` needs to be removed from a method which is annotated with `@ConfigurationProperties`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be hard to make this work - basically by just ignoring @Bean. We should follow up this PR with that

Otherwise two beans will be created and injection will fail.
4. `@NestedConfigurationProperty` can be used but is not required.
Nested property classes work out of the box with inner and outer classes.
5. `@ConstructorBinding` is not supported.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a nice follow up that would also work for Quarkus's @ConfigProperties.

Nested property classes work out of the box with inner and outer classes.
5. `@ConstructorBinding` is not supported.
6. Spring Boot properties conversion is not supported.
7. Random values are not supported
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are random values?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring Boot properties support various expressions in application.properties. One of them are random values where you can set something like this: my.number=${random.int}. Of course, if it's needed it should be a feature of Quarkus properties rather than Spring Boot properties extension

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks!

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@gsmet is there anything that you can spot that doesn't add up?

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the CI config needs to be updated as well: https://github.com/quarkusio/quarkus/blob/master/ci-templates/stages.yml#L362

@geoand
Copy link
Contributor

geoand commented Dec 20, 2019

It's just the (integration test) directory name that needs to be added

@maxandersen
Copy link
Member

does this thing do what I think it does ? adding a quarkus-springboot-properties extension that will pickup springboot keys in application.properties or ?

@geoand
Copy link
Contributor

geoand commented Dec 22, 2019

@maxandersen no.

This allows users to use Spring Boot's @ConfigurationProperties annotation.

@gsmet
Copy link
Member

gsmet commented Dec 22, 2019

I have one question about that one: we created an extension that specifically introduces support for Spring Boot properties. What if we want to introduce more features? We will create one extension per feature? That doesn't seem ideal.

@geoand
Copy link
Contributor

geoand commented Dec 22, 2019

Any ideas on what to call it?

@gsmet
Copy link
Member

gsmet commented Dec 23, 2019

Well, I don't even know if you plan to add more features? But if so, it would probably be "spring-boot" instead of having 5 different extensions with different features.

But I'm not totally sure what our target is here, just raising the issue.

@geoand
Copy link
Contributor

geoand commented Dec 23, 2019

I see your point and I do have the same concerns. However, naming the extension spring-boot would probably lead to massive confusion and a ton of issues being opened asking why this or that spring Boot feature doesn't work.
Another option would be to roll this into Spring DI.
The only problem is that the jar size would increase

@gytis
Copy link
Author

gytis commented Dec 23, 2019

Maybe we could merge the extensions in the future if the number becomes too big? At the end of the day all the Spring and Spring Boot features are marked as preview.

However, merging this extension with Spring DI would not be an ideal scenario IMO. The properties API that is used in this extension comes from Spring Boot project directly. Spring DI on the other had is a separate project and has a much smaller scope.

@geoand
Copy link
Contributor

geoand commented Dec 23, 2019

Maybe we could merge the extensions in the future if the number becomes too big? At the end of the day all the Spring and Spring Boot features are marked as preview.

+1

@geoand
Copy link
Contributor

geoand commented Dec 24, 2019

I propose that for the time being we leave the name as is and leave it in preview state, that way we can change it later on if needed

@gsmet
Copy link
Member

gsmet commented Dec 24, 2019

OK, I suppose I can live with that :).

@gsmet gsmet merged commit b181352 into quarkusio:master Dec 24, 2019
@gsmet gsmet added this to the 1.2.0 milestone Dec 24, 2019
@gytis gytis deleted the spring-boot-properties branch May 7, 2020 14:17
@snowdrop-bot snowdrop-bot mentioned this pull request May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants