如何做自己的服务监控?spring boot 1.x服务监控揭秘

 可运行程序:upload/201901171154545272.gif" alt="复制代码" style="box-sizing: border-box; max-width: 900px; height: auto; border: none !important;" />

        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-actuator</artifactId>            <scope>provided</scope>        </dependency>
复制代码

3.启动spring boot项目

console 截图如下:

4.servlet和filter

  4.1 使用ServletRegistrationBean注册dispatcherServlet

复制代码
/**  * A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+  * container. Similar to the {@link ServletContext#addServlet(String, Servlet)  * registration} features provided by {@link ServletContext} but with a Spring Bean  * friendly design.  * <p>  * The {@link #setServlet(Servlet) servlet} must be specified before calling  * {@link #onStartup}. URL mapping can be configured used {@link #setUrlMappings} or  * omitted when mapping to '/*' (unless  * {@link #ServletRegistrationBean(Servlet, boolean, String...) alwaysMapUrl} is set to  * {@code false}). The servlet name will be deduced if not specified.  *  * @param <T> the type of the {@link Servlet} to register  * @author Phillip Webb  * @since 1.4.0  * @see ServletContextInitializer  * @see ServletContext#addServlet(String, Servlet)  */
复制代码

总结:类似于ServletContext#addServlet(String, Servlet)

查看所有注册的bean

upload/201901171154573460.png" alt="" style="border: 0px; box-sizing: border-box; max-width: 900px; height: auto;" />

注册的流程:

spring-boot-autoconfigure模块spring.facotories的属性org.springframework.boot.autoconfigure.EnableAutoConfiguration=DispatcherServletAutoConfiguration

复制代码
        @Bean(name = DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)         @ConditionalOnBean(value = DispatcherServlet.class, name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)         public DispatcherServletRegistrationBean dispatcherServletRegistration(                 DispatcherServlet dispatcherServlet) {             DispatcherServletRegistrationBean registration = new DispatcherServletRegistrationBean(                     dispatcherServlet, this.webMvcProperties.getServlet().getPath());             registration.setName(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);             registration.setLoadOnStartup(                     this.webMvcProperties.getServlet().getLoadOnStartup());             if (this.multipartConfig != null) {                 registration.setMultipartConfig(this.multipartConfig);             }             return registration;         }
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信