Construction of micro-services outside pigx-visual

 First, the new spring boot Micro Services Module

1) Right-click the new directory in pigx: my-demo

17912888-7657454fca3e212d.png

2) Create module

17912888-bb203ac79cce69b7.png
17912888-af7ef10d7cff7b80.png
17912888-da5fd4571d0baa50.png
17912888-8196f43f8350862f.png
17912888-08b898dd916c12ba.png

Second, delete unnecessary files or directories

my-demo/.mvn

my-demo/mvnw.cmd

my-demo/mvnw

my-demo/src/main/resources/application.properties

my-demo/HELP.md

my-demo/.gitignore

my-demo/my-demo.iml

my-demo/src/test

Third, modify the pom file

1) pom.xml

Pay particular attention to the version number of the module must be commented out, otherwise an exception will be reported in an integrated mybatis-plus

Unsatisfied dependency expressed through field 'baseMapper'; nested exception

Even with

<properties>

        <pigx.version>3.0.0</pigx.version>

 </properties>

Then the application pigx public library

<dependency>

            <groupId>com.pig4cloud</groupId>

            <artifactId>pigx-common-data</artifactId>

            <version>${pigx.version}</version>

</dependency>

Will be given

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"

        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>

        <groupId>com.pig4cloud</groupId>

        <artifactId>pigx</artifactId>

        <version>3.0.0</version>

    </parent>

    <artifactId>my-demo</artifactId>

    <!--<version>0.0.1</version>-->

    <packaging>jar</packaging>

    <description>在pigx-visual之外构建微服务</description>

    <dependencies>

        <!--必须:nacos注册中心客户端-->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>

        </dependency>

        <!--必须:nacos配置中心客户端-->

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>

        </dependency>

        <!--必备:spring-boot web 模块-->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <!--是否需要:undertow容器,灵活的高性能Web服务器,提供包括阻塞和基于NIO的非阻塞机制-->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-undertow</artifactId>

        </dependency>

        <!--mybatis-->

        <dependency>

            <groupId>com.baomidou</groupId>

            <artifactId>mybatis-plus-boot-starter</artifactId>

        </dependency>

        <!--数据库-->

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

        </dependency>

        <!--必备:pigx数据操作-->

        <dependency>

            <groupId>com.pig4cloud</groupId>

            <artifactId>pigx-common-data</artifactId>

        </dependency>

        <!--必备:pigx common核心-->

        <dependency>

            <groupId>com.pig4cloud</groupId>

            <artifactId>pigx-common-core</artifactId>

        </dependency>

        <!--必备:pigx安全模块-->

        <dependency>

            <groupId>com.pig4cloud</groupId>

            <artifactId>pigx-common-security</artifactId>

        </dependency>

        <!--必备:pigx日志-->

        <dependency>

            <groupId>com.pig4cloud</groupId>

            <artifactId>pigx-common-log</artifactId>

        </dependency>

        <!--推荐:pigx swagger api调试接入-->

        <dependency>

            <groupId>com.pig4cloud</groupId>

            <artifactId>pigx-common-swagger</artifactId>

        </dependency>

    </dependencies>

    <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

            <plugin>

                <groupId>com.spotify</groupId>

                <artifactId>docker-maven-plugin</artifactId>

            </plugin>

        </plugins>

    </build>

</project>

2)pigx的pom.xml(父模块增加子模块配置)中增加my-demo

<modules>

    <module>pigx-register</module>

    <module>pigx-gateway</module>

    <module>pigx-auth</module>

    <module>pigx-upms</module>

    <module>pigx-common</module>

    <module>pigx-visual</module>

    <module>my-demo</module>

</modules>

四、新增配置文件

1)my-demo/src/main/resources/bootstrap.yml

server:

  *#  端口不能与其他模块冲突*

*  *port: 5004

spring:

  application:

    name: @artifactId@

  cloud:

    nacos:

      discovery:

        server-addr: ${NACOS-HOST:pigx-register}:${NACOS-PORT:8848}

      config:

        server-addr: ${spring.cloud.nacos.discovery.server-addr}

        file-extension: yml

        shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

  profiles:

    active: dev


2)nacos配置中心新建 my-demo-dev.yml

## spring security 配置

security:

  oauth2:

    client:

      # 配置后才能认证,生产环境建议设置独立的客户端信息

      client-id: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)

      client-secret: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)

      scope: server

3)启动前端配置路由

17912888-e1207128a0b784e4.png

五、修改main方法

package com.mycompany.mydemo;

import com.pig4cloud.pigx.common.security.annotation.EnablePigxFeignClients;

import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer;

import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2;

import org.springframework.boot.SpringApplication;

import org.springframework.cloud.client.SpringCloudApplication;

@EnablePigxSwagger2

@SpringCloudApplication

@EnablePigxFeignClients

@EnablePigxResourceServer

public class MyDemoApplication {

    public static void main(String[] args) {

        SpringApplication.run(MyDemoApplication.class, args);

    }

}

六、创建Controller

package com.mycompany.mydemo.controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

@RestController

@RequestMapping("/demo")

public class DemoController {

    @GetMapping("/hello")

    public String Hello() {

        return "hello demo";

    }

}

七、重启gateway,再启动MyDemoApplication

启动后使用swagger进行api测试

http://pigx-gateway:9999/swagger-ui.html?urls.primaryName=my-demo

Guess you like

Origin blog.csdn.net/weixin_33890526/article/details/90994492