首页 > 其他分享 >springboot 整合 nacos 实现配置文件统一管理 和 服务注册

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

时间:2023-09-13 17:22:56浏览次数:33  
标签:springboot 配置文件 pms -- spring boot nacos org mingx

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)

 

 

标签:springboot,配置文件,pms,--,spring,boot,nacos,org,mingx
From: https://www.cnblogs.com/guanxiaohe/p/17700219.html

相关文章

  • Springboot RocketMQ整合—官方原版
    Doker 技术人自己的数码品牌Doker官网:Doker多克一、添加maven依赖:<dependency><groupId>org.apache.rocketmq</groupId><artifactId>rocketmq-spring-boot-starter</artifactId><version>${RELEASE.VERSION}</version></dependen......
  • 对SpringBoot接口进行操作日志记录
    最近业务有需求要对所有的用户操作进行日志记录,方便管理员查询不同权限级别的用户对系统的操作记录,现有的日志只是记录了异常信息、业务出错、重要功能的执行进行了记录,并不能满足需求要求,最直接的解决方法是在每个接口上去添加log.info之类的代码,但是这种方式对业务代码的切入性......
  • SpringCould总结 | 第八篇 工程加载配置中心的配置文件
    //工程结构//pom文件<projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">......
  • SpringBoot入门(一) springBoot框架搭建和启动
    1.创建maven工程MavenProject      //CODE    <projectxmlns="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.0http://maven.apache.org/xs......
  • SpringBoot教程(二)springboot的配置文件
    一.springboot配置文件的类型application.propertiesapplication.yml项目结构,因为不可以同时使用这两种文件启动时任选一个放到resources下即可 二.properties配置文件的使用packagecom.lpinfo.shop.lpinfoshop;importorg.springframework.beans.factory.annotation.Autowi......
  • springboot发布部署web jar包
    1.在idea中生成jar包文件 2.我这个项目使用的是JavaJDK20,所以要在官网下载这个版本在服务器上安装。https://www.oracle.com/java/technologies/downloads/   有些系统需要重启下服务器才会生效。 3.把第一步生成的 demo-0.0.1-SNAPSHOT.jar文件复制到服务器......
  • Springboot @ConfigurationProperties对象 静态方法调用无效
    一.问题1.springboot使用 @ConfigurationProperties注入对象普通方法调用可以 在静态方法中调用的时候读取不到参数二.文件packagecom.lpinfo.framework.config;@Data@Component@PropertySource("classpath:/oss.properties")@ConfigurationProperties(prefix="oss")......
  • SpringBoot+Mybatis三级查询
    一、概述现有一个需求:查询视频详情。对应三张表,视频表、章节列表、集列表。一个视频对应多个章节,一个章节对应多集视频。请根据视频id查询视频详情,并把视频的章节列表,章节中的集列表都带出来。SpringBoot和MyBatis-plus说明:<!--根模块继承了SpringBoot,子模块也跟着继......
  • nacos redis mysql 服务启动脚本
    nacos#cat/etc/systemd/system/nacos.service[Unit]Description=nacosAfter=network.target[Service]Type=forkingExecStart=/usr/local/src/nacos/bin/startup.shExecStop=/usr/local/src/nacos/bin/shutdown.shPrivateTmp=true[Install]WantedBy=multi-user.......
  • 注册到K8S上的Nacos报错com.alibaba.nacos.api.exception.NacosException: Client not
    契机近期升级SpringCloudAlibaba版本,从2021.0.1.0升级到2021.0.5问题现象注册到K8S平台上2.1.2版本的Nacos报错,错误信息如下:2023-09-1309:29:53.712INFO19988—[main]c.a.n.p.a.s.c.ClientAuthPluginManager:ClientAuthPluginManagerLoadClientAuthServiceco......