-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Closed
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another
Description
Custom endpoints marked with @Endpoint
cannot be marked with @RefreshScope
.
nested exception is java.lang.IllegalStateException: Found two endpoints with the id 'my-endpoint': 'myEndpoint' and 'scopedTarget.myEndpoint'
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)...
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:620)...
How
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
@RefreshScope
@ConditionalOnEnabledEndpoint
public MyEndpoint myEndpoint() {
return new MyEndpoint();
}
@Endpoint(id = "my-endpoint")
public static class MyEndpoint {
@ReadOperation
public String helloWorld() {
return "Hello, World";
}
}
}
The above will cause an exception to be raised.
See this example project: Archive.zip
Where
Spring Boot 2.1.0.RELEASE
Possible Workaround
Commenting out the @RefreshScope
annotation fixes the issue; Not sure if this is an acceptable cavaeat that endpoints may not be refreshable.
Related Issue
See #8462 for a similiar report against Spring Boot 1.5.x
.
I am not certain this is a Spring Boot issue or a Spring Cloud issue; Seems like the culprit may be in ServletEndpointRegistrar
which belongs to Boot, thus the issue here but I'd be happy to move it elsewhere or better yet, with a few pointers I may be able to provide a pull request to remove the issue if you consider this report to a valid problem.
Metadata
Metadata
Assignees
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another