I have a holiday service written during spring boot. I want to get all the endpoints after launch. How can i achieve this? The purpose of this, I want to save all endpoints in db after startup (if they do not already exist) and use them for authorization. These entries will be entered into roles, and roles will be used to create tokens.
You can get RequestMappingHandlerMapping at the beginning of the application context.
public class EndpointsListener implements ApplicationListener { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); applicationContext.getBean(RequestMappingHandlerMapping.class).getHandlerMethods().forEach(/*Write your code here */); } } }
Alternatively, you can also use the Spring boot drive (you can also use the drive, even if you are not using Spring boot), which provides a different endpoint (a mapping endpoint) that lists all the endpoints in json. You can click this endpoint and parse JSON to get a list of endpoints.
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints
You need 3 steps to set all the end points:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
In Spring Boot 2, Actuator ships with most disabled endpoints, only 2 are available by default:
/health /info
If you want to include all endpoints, just set:
management.endpoints.web.exposure.include=*
For more information, refer to:
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
Http: // host / drive / mapping
By the way, in Spring Boot 2 Actuator simplifies the security model by combining it with the application.
For more details, refer to this article:
https://www.baeldung.com/spring-boot-actuators
Source: https://habr.com/ru/post/1267015/More articles:Javascript - regex optimization / replace - javascriptSpring - is it possible to get all the packages registered in @ComponentScan? - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1267012/combining-rows-to-others-in-pandas&usg=ALkJrhjm1YpOPKdBcXWZLBobIFzC_T5gCgAmazon EMR - how to set a timeout for a step - emrJavascript NodeJS 7.9.0 temporary dead zone is decreasing? - javascriptHow to split / reuse layers / variables on different graphs in a tensor stream? - tensorflowImplementing 3D vectors in Python: numpy vs x, y, z fields - pythonTracking class-level Python 2.7.x object attributes to quickly create a numpy array - pythonangular2 ngModel with value from @Input - angularReact-bootstrap bookmarks: Warning. In the context of ` `, ` the generated attributes` id` and `aria-controls` are returned - javascriptAll Articles