In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article shares with you the content of a sample analysis of Springboot management settings. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Spring Boot Admin is a great dashboard for monitoring your Spring Boot applications. However, setting it up is not that simple.
Include a client library connected to the management application in your startup application-this requires that the management application be deployed somewhere public or at least accessible from your application, and let your application know that it is being monitored.
Using cloud discovery means that your application is part of the service discovery infrastructure, such as using microservices
For simpler scenarios, such as a single application running on some IaaS, or deploying your management application on a local machine or some local corporate infrastructure, neither is a good choice. If you don't need cloud discovery yet, it's overkill, and including client libraries introduces the complexity of making the application accessible to the management server, and vice versa. In addition, this two-way dependency sounds wrong.
Fortunately, there is an undocumented but implemented method, SimpleDiscoveryClient, that allows you to simply run Spring Boot Admin with some configuration on any machine and connect it to your Spring Boot application.
The first requirement is to set up spring boot actuator in your startup application. Actuator exposes all the endpoints needed to manage the work of the application. Setting up sounds simple-- you just need to add a bunch of dependencies and maybe specify some configuration parameters, that's all. In fact, in practical applications, this is not easy-- especially with regard to basic authentication of actuator endpoints. You need a separate spring-security (in addition to the existing spring-security configuration) so that only basic authentication is applied to the executor endpoint. For example:
Configuration@Order (99) / / the default security configuration has order 100public class ActuatorSecurityConfigurationextends WebSecurityConfigurerAdapter {@ Value ("${security.user.name}") private String username; @ Value ("${security.user.password}") private String password; @ Override protected void configure (HttpSecurity http) throws Exception {InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager () Manager.createUser (User.withUsername (username) .password (password) .password ("ACTUATOR", "ADMIN") .build (); http.antMatcher ("/ manage/**"). AuthorizeRequests (). AnyRequest (). HasRole ("ACTUATOR"). And (). HttpBasic () and (). UserDetailsService (manager);}}
It's a little counterintuitive, but it works. Not sure if it's idiomatic-with spring security and spring boot, you never know what idiom is. Note-it is said that security.user.name (and password) should be automatically included in a manager, but I can't find it, so I just instantiated one in memory. Note the / manage/** path-in order to have all the actuator endpoints under this path, you need to specify management.context-path=/manage in the application properties file.
Now that the actuator endpoint is set up, we must attach our spring management application. It looks like this:
@ Configuration@EnableAutoConfiguration@PropertySource ("classpath:/application.properties") @ EnableAdminServerpublic class BootAdminApplication {public static void main (String [] args) {SpringApplication.run (BootAdminApplication.class, args);} @ Autowired private ApplicationDiscoveryListener listener; @ PostConstruct public void init () {/ / we have to fire this event in order to trigger the service registration InstanceRegisteredEvent event = new InstanceRegisteredEvent ("prod", null) / / for some reason publising doesn't work, so we invoke directly listener.onInstanceRegistered (event);}}
In general, ApplicationEventPublisher messages should be injected and pushed there instead of calling the listener directly, as shown above. I didn't try to make it work easily, so I solved the problem.
The application.properties file mentioned should be in src/main/resources and look like this:
Spring.cloud.discovery.client.simple.instances.prod [0] .uri = https://your-spring-boot-application-url.comspring.cloud.discovery.client.simple.instances.prod[0].metadata.user.name=spring.cloud.discovery.client.simple.instances.prod[0].metadata.user.password=spring.boot.admin.discovery.converter.management-context-path=/managespring.boot.admin.discovery.services=*
What is that doing? It is using SimpleDiscoveryClient instantiated by automatic configuration. In fact, the client doesn't work until the latest version-- it throws NullPointerException because the metadata (handling usernames and passwords) is always empty. In cloud-commons of 1.2.2, they fixed it:
Org.springframework.cloud spring-cloud-commons 1.2.2.RELEASE
Simply discovering that the client is like this-- you specify the URL that starts the application, which periodically fetches data from the executor endpoint. Why it's not on the record, why it didn't really work until recently-I don't know. In addition, I don't know why you have to send events that trigger discovery manually. Maybe it's not customary, but it doesn't happen automatically, which makes it work.
As usual, things like "working" and "simple settings" have never been like that. If you have something a little more complex than hello world, you have to dig into some obscure classes and "off-road". Fortunately, in this case, it does work, rather than requiring a bad solution.
Thank you for reading! This is the end of this article on "sample Analysis of Springboot Management Settings". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.