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

Add AutoConfiguration.imports for basic spring boot v3.0 support #775

Merged
merged 3 commits into from
Dec 13, 2022

Conversation

genuss
Copy link
Contributor

@genuss genuss commented Oct 22, 2022

Hello!
I'd like to add the new style of auto-configurations declaration which appeared in spring boot 2.7 This version of spring supports old-style too, but spring boot 3.x won't support spring.factories anymore. I don't delete auto-configurations from spring.factories yet, as current baseline is spring boot 2.6.x.
I'd like to merge this as I'm interested in preparing to 3.x release and this is a first step of it.

…figurations declaration appeared in spring boot 2.7.0
@ST-DDT
Copy link
Collaborator

ST-DDT commented Oct 22, 2022

Nice! Have you tested whether having both causes issues?
E.g. beans being initialized twice...

@ST-DDT ST-DDT added enhancement A feature request or improvement incompatibility Incompatibilities between components or versions labels Oct 22, 2022
@genuss
Copy link
Contributor Author

genuss commented Oct 23, 2022

Well, I didn't do thorough testing, but checked all my in-house autoconfigurations from work and some open-source ones. And I didn't find anything wrong.
For duplicate autoconfigurations there is AutoConfigurationImportSelector#removeDuplicates, so I don't think there can be issues

@ST-DDT ST-DDT mentioned this pull request Oct 26, 2022
@amitbansal26
Copy link

When this will be merged ?

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 16, 2022

When @yidongnan or I have time to test and review it.
I hope soonish.

@QB-NemanjaTozic
Copy link

QB-NemanjaTozic commented Nov 28, 2022

Just to note that since Spring Boot 3 doesn't support spring.factories, the library doesn't currently work out-of-the-box with Spring Boot 3.0.0.

Workaround until this is merged is to import all of the configurations that are listed in current spring.factories, ie:

@Configuration
@ImportAutoConfiguration({
    net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration.class,
    net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration.class,
    net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration.class,
    net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration.class,
    net.devh.boot.grpc.client.autoconfigure.GrpcClientTraceAutoConfiguration.class,
    net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration.class,

    net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration.class,
    net.devh.boot.grpc.common.autoconfigure.GrpcCommonTraceAutoConfiguration.class,

    net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration.class,
    net.devh.boot.grpc.server.autoconfigure.GrpcServerTraceAutoConfiguration.class
})
class GrpcConfig {}

@amitbansal26
Copy link

have you created any sample project using spring boot 3 with this library . If you can provide the link it would be nice .

@QB-NemanjaTozic
Copy link

@amitbansal26
This is a very simple project that I do for some internal reasons (on my private profile) and has a very simple use of the library, but hope it's something useful for you:

https://github.com/NemanjaT/airsoft-iam

This is the workaround I was talking about:
https://github.com/NemanjaT/airsoft-iam/blob/main/src/main/java/com/ntozic/airsoft/iam/config/grpc/GrpcConfig.java

@amitbansal26
Copy link

@amitbansal26 This is a very simple project that I do for some internal reasons (on my private profile) and has a very simple use of the library, but hope it's something useful for you:

https://github.com/NemanjaT/airsoft-iam

This is the workaround I was talking about: https://github.com/NemanjaT/airsoft-iam/blob/main/src/main/java/com/ntozic/airsoft/iam/config/grpc/GrpcConfig.java

Thanks So much this surely helps !!!

@renatosilvarosa
Copy link

Other workaround: create your own org.springframework.boot.autoconfigure.AutoConfiguration.imports file under META-INF/spring and add the list of classes currently in spring.factories.

@ST-DDT ST-DDT added this to the 2.15.0 milestone Dec 13, 2022
@ST-DDT ST-DDT changed the title Add *AutoConfiguration.imports files to support new style of auto-configurations declaration appeared in spring boot 2.7.0 Add AutoConfiguration.imports for basic spring boot v3.0 support Dec 13, 2022
@ST-DDT ST-DDT merged commit 9f3ec84 into grpc-ecosystem:master Dec 13, 2022
@bdevapatla
Copy link

@configuration
@ImportAutoConfiguration({
net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration.class,
net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration.class,
net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration.class,
net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration.class,
net.devh.boot.grpc.client.autoconfigure.GrpcClientTraceAutoConfiguration.class,
net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration.class,

net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration.class,
net.devh.boot.grpc.common.autoconfigure.GrpcCommonTraceAutoConfiguration.class,

net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration.class,
net.devh.boot.grpc.server.autoconfigure.GrpcServerTraceAutoConfiguration.class

})

This file doesn't exist anymore. Also, has this config already been merged to grpc-spring-boot-starter?

@ctdillon
Copy link

ctdillon commented Mar 26, 2023

@bdevapatla It's been merged, but apparently hasn't made it into a tagged release yet. You can create this file (/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports) in your own project, and use that until it is.

@genuss genuss deleted the feature/autoconfiguration branch April 17, 2023 13:03
@danHayworth
Copy link

did anyone find that after adding these imports you get the Server port already in use when running mvn test ?

@kaisermario
Copy link

Does anyone has an idea when we can expected a new tagged release including this changes?

@MissakaI-ObjectOne
Copy link

For anyone having the issue io.grpc.StatusRuntimeException: UNAVAILABLE: Could not find server: myServer even after adding the auto configuration to match the Spring Boot 3 in you grpc client

Try adding @EnableConfigurationProperties(value = {GrpcChannelsProperties.class}) to your grpc client.

@lmcdasi
Copy link

lmcdasi commented Aug 9, 2023

I do not think having GrpcConfig with all AutoConfig is correct. Not all projects have grpc client & server at the same time.

If I have grpc client or grpc server, then I will end up having a meta-data exception since the corresponding jar file is missing.

Until it get's fix I think that each project needs to add:

META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

containing the exact set of the AutoConfig files, client or server or both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature request or improvement incompatibility Incompatibilities between components or versions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet