springcloud uses nacos to build a registration center

I won’t go into details about nacos installation here, ( Nacos download and build environment_You are not a lemon, why are you sad 142’s blog-CSDN blog )

You can also go to the Internet to install it. Here we mainly talk about the construction. We need to manually start nacos.

Enter (.\startup.cmd -m standalone), and the icon will appear on behalf of ok



 

 The first is the dependencies required by the parent project. It should be noted that the version must correspond to the above. Here and the above

 <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
<!--        <spring-boot.version>2.3.12.RELEASE</spring-boot.version>-->
        <spring-cloud-alibaba.version>2.2.9.RELEASE</spring-cloud-alibaba.version>
    </properties>

<!--    依赖管理-->
    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Then the dependencies that the subprojects need to add


<!--子项目添加依赖-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

Configuration of submodules



 And the writing of controller


@RestController
@RequestMapping("/provider")
public class ProviderController {
    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/add")
    public String hello() {
        System.out.println("下单成功我是8050端口我要去连接8060端口");
        String forObject = restTemplate.getForObject("http://service-const/stock/chd", String.class);
        System.out.println("通信成功" + forObject);
        return "hello word" + forObject;
    }


}


The writing of the controller


@RestController
@RequestMapping("/stock")
public class ConstController {

@RequestMapping("/chd")
public String hello() {
System.out.println("陈厚德傻逼这是通信,我是8060端口");
return "陈厚德傻逼嘿嘿嘿这个用来通信";
}



}

All the work has been completed here. Start directly, the overall project structure is as follows



We enter localhost:8048 in the webpage address,


Seeing the two registered by myself means success, I hope to help you friends 

Guess you like

Origin blog.csdn.net/weixin_69218754/article/details/131108598