This is the first day of my participation in Gwen Challenge.

This article is participating in “Java Theme Month – Java Development in Action”, see the activity link for details

My open source Spring Cloud project PassJava has always worked well on Windows. Recently, I switched to Mac M1, and I want to run this project on M1. After all, my Windows runs hot, so I should experience the performance of M1.

Due to poor compatibility of M1, I encountered many problems when running this project from 0, for example, MySQL tool often failed to open and front-end Vue project failed to start. Therefore, I made a record for these difficult and complicated problems, which I believe will be helpful for students using M1.

I uploaded the back end, front end, small program to the same warehouse, you can access through Github or code cloud. The address is as follows:

Making: github.com/Jackson0714…

Yards cloud: gitee.com/jayh2018/Pa…

Accompanying tutorial: www.passjava.cn

The overall architecture is as follows:

The main contents of this paper are as follows:

1. Configure Nacos

Nacos is a configuration center and registry that must be started.

1.1 Download Address

Nacos download address:

https://github.com/alibaba/nacos/releases
Copy the code

The latest version is 2.0.0-Bugfix. After downloading it, I successfully started it, but I couldn’t access the Nacos background. I suspected that there was something wrong with the local environment, so I changed to a lower version 1.4.1, which worked normally. In addition, the version 1.2.1 THAT I was using on a Windows machine worked fine when I copied it to a Mac.

1.2 start Nacos

Go to the nacos root directory and run the following command:

sh startup.sh -m standalone
Copy the code

The result is as follows:

See Nacos is starting withi standalone. Note: Successful startup does not mean normal operation.

Next, access the nacOS backend management system:

http://127.0.0.1:8848/nacos/#/login
Copy the code

The account and password are nacos.

1.3 Adding a namespace

Add namespaces for 7 microservices:

Fields to be filled in when creating a namespace:

1.4 Adding the Question Microservice Configuration

Add several micro-service configurations to the configuration list. For now, ensure that question micro-service and ThirdParty micro-service are configured.

As shown in the figure below, add three configuration items: data source, MyBatis configuration, and others. See this article for detailed configuration parameters: SpringCloud integration Nacos configuration center.

1.5 Adding the ThirdParty microservice Configuration

Ali cloud OSS is mainly configured to save pictures. The configuration is as shown in the figure below. You need to log in to Ali Cloud and apply for OSS to obtain the key. See this article on SpringCloud integrating OSS object Storage.

2. Initialize data

Creating databases, tables, and initializing data is all you need to do. It’s easier to download a MySQL client and then find a Mac client that works. Here’s how to install the software.

1.1 Installing MySQL for Mac

MySQL > Install MySQL for MAC

https://dev.mysql.com/downloads/mysql/
Copy the code

Just choose the first version, which is compatible with Mac M1

Packages for Catalina (10.15) are compatible with Big Sur (11)
Copy the code

Download and click Install. After the installation is successful, go to system preferences to find MySQL and click Open.

MySQL 8.0.23 MySQL 8.0.23 MySQL 8.0.23

! []

2.2 Installing the Mac GRAPHICAL MySQL Interface

2.2.1 Workbench cannot run on M1

I tried installing workbench and it didn’t work.

2.2.2 Squel Pro will not run on M1

After installing Squel Pro, the application crashed while switching databases.

2.2.3 Navicat

After the two crashes, I finally downloaded a trial version of Navicat, which was free for 14 days, enough to initialize the data.

Download address:

http://www.navicat.com.cn/download/navicat-for-mysql
Copy the code

Download the latest version of macOS 15, which is compatible with the M1 chip.

Then I need to execute three SQL files, which I have uploaded to the warehouse,

/passjava-platform/data/sql
Copy the code

After executing the above three files in sequence, six databases, one system database, and five business databases are generated.

Third, start microservices

It mainly starts four core services: gateway micro-service, topic micro-service, third-party micro-service and system management micro-service.

The architecture diagram is as follows:

At present, these microservices have been integrated with Nacos, OpenFeign, Gateway, unified exception handling, link tracing, Redis, etc.

Start is based on IDEA development tools directly started, so you need to download IDEA.

3.1 Downloading and Installing the IDEA

IDEA I installed is the flagship version 2020.3, trial version for 30 days. You can download the free Community edition, which is functional enough.

Performance is very fast, my Windows configuration: ThinkPad, 32GB RAM, 1TB SSD, starting a microservice takes more than 10 seconds. The Mac takes three seconds.

Official website download address:

https://www.jetbrains.com/idea/download/#section=mac
Copy the code

3.2 Starting the System Management Service

Our background framework is the renren framework, the main function is the background login, system management functions, so we must start renren-fast service to use background management.

You can start the Service RenrenApplication. If the Service is successfully started, the following message will be displayed:

Renren-fast service exposes port 8080, but this port is not visible to the front end. The front end API is port 8060 through the gateway. Forward front-end requests to Port 8060 of Renren-Fast, such as login requests. Note: data must be initialized to start successfully.

3.3 Starting the Gateway

There are no special requirements for gateway microservices, I have all configured, just start it up. In addition, if the port is occupied, run the following command:

lsof -i:8060
kill-9 < process ID >Copy the code

Gateway microservice exposes port 8060, as shown below after startup:

3.4 Starting the Topic Service

Topic service is the core module, and many practical cases are explained based on this module. Before starting the service, you need to configure the connection to the MySQL database.

3.4.1 Configuring the Database Connection

File path: / passjava - question/SRC/main/resources/application. The yml spring: a datasource: driver - class - name: Com. Mysql. Cj, JDBC Driver url: JDBC: mysql: / / 127.0.0.1:3306 / passjava_qms? useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT username: root password: xxxCopy the code

We can also use nacOS to configure:

3.4.2 Starting the Topic Service

IDEA tool can be directly started, the exposed port is 11000, after starting as shown below:

3.4.3 Test topic service

Use Postman to test whether gateway + title microservice is working properly:

Because I have data in my database, it will return a lot of data, so you can add data later.

3.5 Starting third-party Services

This third party does not refer to the services of the other party, but I put the services that interact with the third party middleware in this service, such as the operation of Ali Cloud OSS (object storage).

The name of the service is passjava-thirdparty. In addition, note that OSS requires you to apply for a free quota on the official website of Ali Cloud.

After successful startup, the following figure shows:

4. Start the Admin background

The technical selection of Admin management background is still Vue, so you need to use NPM tools to install dependencies.

4.1 Installing the NPM and NVM

Install NPM using Homebrew

brew install npm
Copy the code

Install NVM using Homebrew

brew install nvm
Copy the code

4.2 Changing the Mirror Source

The default NPM uses the official mirror source, and we switched to the domestic Taobao mirror source.

npm install -g cnpm --registry=https://registry.npm.taobao.org --verbose
Copy the code

4.3 installation node_module

The repository does not upload the dependency packages together. Because the dependency packages are too large, you can run the following command to install the dependency packages locally. This is one-time and does not need to be executed later.

Go to passjava-platform/passjava-portal and run the following command to install dependencies:

cnpm install
Copy the code

Starting the Front-end Portal

npm run dev
Copy the code

Node Sass is not compatible with the current system:

Node Sass does not yet support your current environment: OS X Unsupported architecture (arm64) with Unsupported runtime (88)
Copy the code

Uninstall Node Saas first, according to the solution available online

cnpm uninstall node-sass
Copy the code

However, I failed to install chromeDriver (the current operating system is not compatible). According to the online solution, I installed it separately, but it still indicates that the 64-bit system is not compatible. Therefore, I put “Chromedriver” in package.json file: “2.27.2” deleted, problem solved! The dependency configuration has been removed in the latest code.

Install node_modules before deleting

rm -rf ./node_modules/
Copy the code

Uninstall Node-sass again:

cnpm uninstall node-sass
Copy the code

After the uninstallation, install Node-sass

cnpm install node-sass  --unsafe-perm --save-dev
Copy the code

Reinstall dependencies

cnpm install
Copy the code

4.4 Starting the Background

To start the background, run the following command in the root directory:

npm run dev
Copy the code

After the startup is successful, the browser is automatically opened and the address is http://localhost:8081

4.5 Logging In to the Background

Both the account and password are admin. Enter the verification code to log in. Note: If the verification code does not appear, it indicates that the RenrenApplication microservice is abnormal. Check the log printed in IDEA.

The background login interface is as follows:

4.6 Adding a Topic category

First of all, we need to classify the topic, click New type in the background, as shown in the picture below:

Note: Before uploading the image, you need to start the ThirdParty micro-service, and the OSS configuration is correct.

4.7 Adding interview questions

Five, the other

5.1 Unadapted Mirrors

To use Elasticsearch and Kibana in my open source project, I need to run them on Docker. These images are not yet available on M1.

5.2 Front-end applets

The development and testing of small program is not demonstrated here, M1 development of small program is completely no problem ~

5.3 Unadded Middleware

Because this article is only for the demonstration of core functions, there are some middleware not mentioned, such as configuring Redis, link tracking, etc. These functions do not affect the use of Spring Cloud on M1, so they will be further explained in subsequent articles.

The next combat Redis is also arranged, please look forward to it.