Spring Cloud Alibaba + Dubbo2.7 + Nacos2.0 built from scratch (1)

@[TOC](Spring Cloud Alibaba + Dubbo2.7 + Nacos2.0 built from scratch (1))

Preface

Overall entrance:
https://blog.csdn.net/lwb314/article/details/108277732

Quick setup

  1. Build tool address: http://start.aliyun.com
    Insert image description here
  2. Choose the most basic dependency
    Insert image description here

code

  1. Delete the code automatically generated by IDEA, leaving only the startup class. I changed the format of the bootstrap.properties file to bootstrap.yml. The code modification is as follows:
spring:
  application:
    name: demo-dubbo-service
  cloud:
    nacos:
      server-addr: localhost:8848
      config:
        file-extension: yml
  1. Add nacos configuration, the two properties spring.application.name and file-extension are related to the writing method of nacos configuration center. The data ID configured in nacos is spring.application.name+file-extension as the suffix
    Insert image description here
  2. Start class printing and you can successfully obtain the test.t1 configuration.
package com.lwb.demo.dubbo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class DemoDubboApplication {
    
    

    @Value("${test.t1}")
    String value;

    @PostConstruct
    public void init() {
    
    
        System.out.println(value);
    }

    public static void main(String[] args) {
    
    
        SpringApplication.run(DemoDubboApplication.class, args);
    }

}

Guess you like

Origin blog.csdn.net/lwb314/article/details/118437710