随笔(四)--dubbo-provider引入数据源druid

随笔三

一、引入druid所需的jar包


        
        
            com.alibaba
            druid
            1.1.20
        


        
        
            org.springframework.boot
            spring-boot-starter-web
            2.1.6.RELEASE
        

        
        
            mysql
            mysql-connector-java
            5.1.47
        

        
        
            log4j
            log4j
            1.2.17
        

二、druid的配置类,并默认配置

package com.footprint.healthId.hosp.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @auther footprint
 * @date 2019/9/9
 */
@Configuration
@ConfigurationProperties(prefix = "health.dubbo.provider", ignoreUnknownFields = true, ignoreInvalidFields = false)
public class ProviderConfiguration {
    // dubbo provider's application name
    private String applicationName = "dubbo-provider";
    // dubbo provider register address
    private String registryAddr = "zookeeper://127.0.0.1:2181";
    // dubbo provider protocol port
    private Integer protocolPort = 20880;
    // dubbo provider protocol name
    private String protocolName = "dubbo";

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getRegistryAddr() {
        return registryAddr;
    }

    public void setRegistryAddr(String registryAddr) {
        this.registryAddr = registryAddr;
    }

    public Integer getProtocolPort() {
        return protocolPort;
    }

    public void setProtocolPort(Integer protocolPort) {
        this.protocolPort = protocolPort;
    }

    public String getProtocolName() {
        return protocolName;
    }

    public void setProtocolName(String name) {
        this.protocolName = name;
    }

    @Bean
    public ApplicationConfig beanApplicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName(applicationName);
        return applicationConfig;
    }

    @Bean
    public RegistryConfig beanRegistryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(registryAddr);
        return  registryConfig;
    }

    @Bean
    public ProtocolConfig beanProtocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName(protocolName);
        protocolConfig.setPort(protocolPort);
        return protocolConfig;
    }

}

三、使用注意

当配置文件生效后,可访问:........./druid/ 进入的监控平台。
admin admin

你可能感兴趣的:(随笔(四)--dubbo-provider引入数据源druid)