springboot 整合 nacos 实现配置文件统一管理 和 服务注册

1.我使用的是 nacos-server-1.4.1 

直接启动nacos 没有配置数据库那些

.\startup.cmd -m standalone

2.启动后在nacos中创建命名空间 配置文件

 注意命名空间的id 我是自己定义的 还有 group 到时候配置错了服务又不会报错 只是会读取不到

3.springboot配置

 server-addr 我一开始配置成了 http://localhost:8848/ 找了三四个小时问题 更换springboot版本 更换springcloud版本 添加 spring-cloud-starter-bootstrap 依赖什么的 吐了!

4.附上我的pom依赖 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>mingx-pms</artifactId>
        <groupId>org.mingx.center</groupId>
        <version>1.0.0-RELEASE</version>
    </parent>

    <artifactId>pms-boot</artifactId>
    <version>1.0.0-RELEASE</version>
    <packaging>jar</packaging>
    <description>PMS BOOT SERVER</description>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- Spring 依赖 Start -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Spring 依赖 End -->

        <!-- 基础工具包 -->
        <dependency>
            <groupId>org.mingx.center</groupId>
            <artifactId>pms-base</artifactId>
        </dependency>

        <!--PMS 接口定义-->
        <dependency>
            <groupId>org.mingx.center</groupId>
            <artifactId>pms-entities</artifactId>
        </dependency>

        <!--PMS 接口定义-->
        <dependency>
            <groupId>org.mingx.center</groupId>
            <artifactId>pms-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mingx.center</groupId>
            <artifactId>pms-domain</artifactId>
        </dependency>

        <!--minex UapSDK-->
        <dependency>
            <groupId>com.mxny</groupId>
            <artifactId>uap-sdk</artifactId>
        </dependency>

        <!-- spring-retry-->
        <dependency>
            <groupId>org.springframework.retry</groupId>
            <artifactId>spring-retry</artifactId>
        </dependency>

        <!-- Apache POI -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency>

        <!-- Apache POI OOXML -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>

        <!-- lorry OSS-->
<!--        <dependency>-->
<!--            <groupId>org.lorry.starter</groupId>-->
<!--            <artifactId>oss-spring-boot-starter</artifactId>-->
<!--            <version>1.0.0-RELEASE</version>-->
<!--        </dependency>-->

    </dependencies>

    <build>
        <plugins>
            <!-- maven install时跳过单元测试 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.9.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <mainClass>com.mingx.pms.PmsApplication</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <encoding>UTF-8</encoding>
                    <parameters>true</parameters>
                </configuration>
            </plugin>

        </plugins>

<!--        <resources>-->
<!--            <resource>-->
<!--                <directory>lib</directory>-->
<!--                <targetPath>BOOT-INF/lib/</targetPath>-->
<!--                <includes>-->
<!--                    <include>**/*.jar</include>-->
<!--                </includes>-->
<!--            </resource>-->
<!--            <resource>-->
<!--                <directory>src/main/resources</directory>-->
<!--                <targetPath>BOOT-INF/classes/</targetPath>-->
<!--            </resource>-->
<!--        </resources>-->

        <!--正式环境:shengchanguanli-->
        <finalName>shengchanguanli</finalName>
    </build>

    <!--  配置环境  -->
<!--    <profiles>-->
<!--        <profile>-->
<!--            &lt;!&ndash; 开发 &ndash;&gt;-->
<!--            <id>dev</id>-->
<!--            <activation>-->
<!--                <activeByDefault>true</activeByDefault>-->
<!--            </activation>-->
<!--            <properties>-->
<!--                <activatedProperties>dev</activatedProperties>-->
<!--            </properties>-->
<!--        </profile>-->
<!--        <profile>-->
<!--            &lt;!&ndash; 测试 &ndash;&gt;-->
<!--            <id>test</id>-->
<!--            <properties>-->
<!--                <activatedProperties>test</activatedProperties>-->
<!--            </properties>-->
<!--        </profile>-->
<!--        <profile>-->
<!--            &lt;!&ndash; 准生产 &ndash;&gt;-->
<!--            <id>pre</id>-->
<!--            <properties>-->
<!--                <activatedProperties>pre</activatedProperties>-->
<!--            </properties>-->
<!--        </profile>-->
<!--        <profile>-->
<!--            &lt;!&ndash; 生产 &ndash;&gt;-->
<!--            <id>prod</id>-->
<!--            <properties>-->
<!--                <activatedProperties>prod</activatedProperties>-->
<!--            </properties>-->
<!--        </profile>-->
<!--    </profiles>-->

</project>

最后 程序启动起来了 nacos也注册上了(记得启动类@EnableDiscoveryClient)

 

 

posted @ 2023-09-13 17:13  官萧何  阅读(321)  评论(0)    收藏  举报