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

InstanceRegisteredEvent can implement ResolvableTypeProvider interface for better convenience #1322

Open
XhstormR opened this issue Jan 17, 2024 · 1 comment · May be fixed by #1468
Open

Comments

@XhstormR
Copy link

XhstormR commented Jan 17, 2024

Due to Java type erasure, currently I have to manually determine the type of the event's config when listening to this event:

@Component
class EurekaInstanceConfigPostProcessor(
    private val eureka: EurekaRegistration,
) : ApplicationListener<InstanceRegisteredEvent<*>> {

    override fun onApplicationEvent(event: InstanceRegisteredEvent<*>) {
        if (event.config is EurekaInstanceConfigBean){
            eureka.applicationInfoManager.registerAppMetadata(......)
        }
    }
}

If InstanceRegisteredEvent can implement ResolvableTypeProvider, i can directly listening and set it's config type:

@Component
class EurekaInstanceConfigPostProcessor(
    private val eureka: EurekaRegistration,
) : ApplicationListener<InstanceRegisteredEvent<EurekaInstanceConfigBean>> {

    override fun onApplicationEvent(event: InstanceRegisteredEvent<EurekaInstanceConfigBean>) {
        eureka.applicationInfoManager.registerAppMetadata(......)
    }
}

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/ResolvableTypeProvider.html

quaff added a commit to quaff/spring-cloud-commons that referenced this issue Feb 7, 2025
@quaff
Copy link
Contributor

quaff commented Feb 7, 2025

It should be fixed by #1468.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants