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 · 0 comments

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

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

No branches or pull requests

2 participants