@[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
- Build tool address: http://start.aliyun.com
- Choose the most basic dependency
code
- 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
- 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
- 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);
}
}