dubbo监控服务 获得运行在dubbo上的服务信息

dubbo监控服务

原版的项目结构

在这里插入图片描述

因原版的项目比较久远 还采用的是web.xml来初始化配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <display-name>Dubbo monitor</display-name>
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.handu.open.dubbo.monitor.config.MonitorConfig</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>springServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

代码中可以看出除了一些基本spring配置额外的就是加载了MonitorConfig这个配置文件

/**
 * Copyright 2006-2015 handu.com
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.handu.open.dubbo.monitor.config;

import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

/**
 * MonitorConfig
 *
 * @author Jinkai.Ma
 */
@Configuration
@ComponentScan(basePackages = {
   "com.handu.open.dubbo.monitor"}, includeFilters = {
   @ComponentScan.Filter(value = Service.class)})
@Import({
   WebConfig.class, DubboConfig.class, MyBatisConfig.class, Security.class})
@PropertySource("classpath:/application.properties")
public class MonitorConfig {
   
}

点进去发现其实就是
1.初始化了包扫描 2.加载了一些基本的配置类 3.加载了application.properties文件
与dubbo有关系的其实主要就是DubboConfig.class 和application.properties这两个文件

/**
 * Copyright 2006-2015 handu.com
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.handu.open.dubbo.monitor.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.AnnotationBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * DubboConfig
 *
 * @author Jinkai.Ma
 */
@Configuration
public class DubboConfig {
   

    private static final String REGISTRY_ADDRESS = "dubbo.registry.address";
    private static final String APPLICATION_NAME = "dubbo.application.name";
    private static final String APPLICATION_OWNER = "dubbo.application.owner";
    private static final String PROTOCOL_PORT = "dubbo.protocol.port";

    @Autowired
    private Environment env;

	//向spring容器中注册一个包扫描的bean
    @Bean
    public static AnnotationBean annotationBean() {
   
        AnnotationBean annotationBean = new AnnotationBean();
        annotationBean.setPackage("com.handu.open.dubbo.monitor");
        return annotationBean;
    }
	//向spring容器注册一个服务配置bean声明服务的名字和服务的所属 这两个值无所谓只是用来区别在dubbo中的服务名
    @Bean
    public ApplicationConfig applicationConfig() {
   
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName(env.getProperty(APPLICATION_NAME, "dubbo-monitor"));
        applicationConfig
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值