Technology Sharing

Guide to upgrading existing SpringBoot backend projects to Yudao-Cloud

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Guide to upgrading existing SpringBoot backend projects to Yudao-Cloud



  1. Start the Yudao framework
    • rear end:Quick Start (Backend Project)
    • front end:Quick Start (Backend Project)
    • Notice:
      • You must download Redis and Nacaos. There is a tutorial in the backend quick start.

      • The command to start nacos is wrong in the tutorial. To start nacos without cluster deployment, use the following command

        startup.cmd -m standalone
        
        • 1
  2. Learn to create a new service (once you have learned how to create a new service, you can migrate the old business)
    • Tutorial:New Service

      There are several problems in the tutorial. Some of them have been found, and some have not been found yet. However, it does not affect the follow-up. It is just necessary to understand it, which is helpful for understanding the overall architecture of the project.

      • Different packets have different routing requests

        This involves request routing forwarding. Please see here for the implementation method-> Video Link

      • After starting the demo service, the swagger document cannot be opened using knife4j and an error is generated (unresolved but not affecting)

        Front-end error

        Backend error

      • The Test interface in the tutorial is incorrect

        Even if authorization and tenants are simulated, the request cannot be completed according to the yml file provided previously, so an error will be returned here

        {
            "code": 401,
            "data": null,
            "msg": "账号未登录"
        }
        
        • 1
        • 2
        • 3
        • 4
        • 5
      • After modifying the gateway configuration file and adding the demo route, the document says that the admin and app Test interfaces can be tested normally, but please note: this does not work!

        Because the tenant is not closed and the Authorization field is not added, the returned result is still not acceptable!

    • Modify the yml configuration file in yudao-cloud
      • Routing and forwarding

        Modify application.yaml in gateway (this is in the tutorial of creating a new service)

        Add toRouting forwarding rules, so that the request is forwarded correctly

        Add toKnife4j routing forwarding rules, so that you can view the swagger document normally ([knive4j's official tutorial)

      • Turn off tenantsSaaS Multi-tenancy [Field Isolation]

        Modify application.yaml of biz in system

        Turn off the tenant (if your old project does not involve tenants, my current understanding is that each microservice needs to modify this place to turn off the tenant, otherwise it will report the error "The requested tenant identifier was not passed, please check"!)

        First, turn off the tenant function, but that is not enough. You also need to add rules to ignore URLs to ignore all URLs!!!

        There is another field to be changed on the front end (in .env). The field name is different from that in the document, so the global search in the document cannot find it.

      • Token Authentication

        CheckFunctional permissionsDocument, modify application-local.yaml of biz in system

        Theoretically, you can enable the Token simulation mechanism and set the Token prefix of the Token simulation mechanism, but it is useless in practice. I will change it to respect the tutorial.

    • Add the jar package required by the business to the project
      • Please note that when adding jar packages, it is easy to cause dependency conflicts with the original Maven architecture of Yudao (especially knive4j), and dependencies need to be excluded

        <dependency>
            <groupId>xx.xx.xx</groupId>
            <artifactId>xx-xx-spring-boot-starter</artifactId>
            <version>1.0.19</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-autoconfigure</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.github.xiaoymin</groupId>
                    <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
        • 21
        • 22
        • 23
    • Test whether the new service is responsive
      • Log in and get a token for authentication

      • Test app-test

      • Testadmin-test

        Note the authorization authentication in the request header

        Authorization:Bearer f4fb08efe73a4a98bb248da70f4cc514
        
        • 1