1. 概述

此文档讲解如何在jpaas平台中新建一个新的微服务进行开发,相关配置进行讲解。

2. 操作步骤

2.1.新建Module

2.2 类型选MAVEN

2.3.Parent选择Jpaas-service

2.4.代码结构如下

2.5.bootstrap.yml

2.6 . application.yml-数据库配置

2.7. application.yml-swagger文档和seata配置

2.8. mybatis扫描配置

2.9. 路径可用配置

2.10. nacos地址配置


还要注意增加nacos.namespace参数配置

2.11. pom.xml配置

<?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">
    <parent>
        <artifactId>jpaas-service</artifactId>
        <groupId>com.redxun</groupId>
        <version>1.1.RELEASE</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>jpaas-demo</artifactId>

    <dependencies>
        <!-- 公共实体类模块 -->
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-config</artifactId>
        </dependency>
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-common-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-db-spring-boot-starter</artifactId>
            <version>1.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-redis-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-ribbon-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-sentinel-spring-boot-starter</artifactId>
        </dependency>
        <!-- swagger -->
        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-swagger2-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>

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

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>

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

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



        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-web-spring-boot-starter</artifactId>
            <version>1.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>

        </dependency>

        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-share</artifactId>
            <version>1.1.4.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>com.redxun</groupId>
                    <artifactId>jpaas-common-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.redxun</groupId>
            <artifactId>jpaas-common-core</artifactId>
            <version>1.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-spring-boot-starter</artifactId>

        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>

        </dependency>

        <dependency>
            <groupId>io.seata</groupId>
            <artifactId>seata-all</artifactId>

        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
        <finalName>${project.artifactId}</finalName>
    </build>
</project>

2.12.NACOS配置数据库信息

2.13.增加路由配置


2.14.效果图

3. 需要注意的问题

3.1 自定义包名的问题

在开发代码时,大部分都需要使用自己公司的包名进行开发,这个时候可能遇到各种错误,错误的原因时没有找到 com.redxun的包。

解决办法如下:

@EnableFeignInterceptor
@EnableFeignClients(basePackages = {"com.redxun"})
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"com.redxun","com.misoft"})
public class JPaasDemoApplication {

    public static void main(String[]args) {
        SpringApplication.run(JPaasDemoApplication.class, args);
    }


    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(
            @Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }
}

增加两个扫描即可以解决。

3.2 项目框架代码下载

DEMO示例代码可以和我司联系。
http://dev.redxun.cn:7990/scm/jpaas_modules/jpaas-demo.git

文档更新时间: 2021-09-07 14:39   作者:csx