springboot 配置nacos

1.新建springboot 单体项目

2.添加依赖

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--============Nacos===========-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <!-- 项目中用到了Feign注解,引入此包 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Greenwich.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!--结束-->
        <!--本地order服务jar-->
        <dependency>
            <groupId>com.ld.order</groupId>
            <artifactId>orderserver</artifactId>
            <version>1.0.1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
            <version>2.3.5.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

3.打包服务

mvn install:install-file -Dfile=D:\demo\order-server\target\order-0.0.1-SNAPSHOT.jar -DgroupId=com.ld.order -DartifactId=orderserver -Dversion=1.0.1 -Dpackaging=jar

4.启动类添加注解

@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
@ComponentScan (basePackages = {"com.example.demo","com.user.demo"})


版权声明:本文为qq_25190901原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。