“Ruoyi” is an open source project that I feel is standard among outsourcing companies and is used by all of them. The README feels like a little tidbit by an Alibaba employee after work. For SprintBoot, I personally feel that it is too heavy-duty, but people have developed an ecology, so it is not so easy to finish it. However, with the acquisition of VMware by Broadcom, the direction of Spring Framework is still unclear.
Today we will try to build this high-star project. I don’t like IDE very much. When it comes to Java, we should try to avoid it. It should be enough for us to use vim. We don’t write much code and just build the environment. I just don’t have mysql at hand, and I’m too lazy to install mariadb; since I used proot, I don’t even bother to use heavy tools like docker. The image takes up too much space, and the runtime is not busybox. There is no point in giving a set of glibc; I thought of a lightweight database. sqlite, then that’s it, use it to run “Ruoyi”.
Download code and tools
To save trouble, let’s take a look at the stand-alone version of “Ruoyi” first.
https://gitee.com/y_project/RuoYi
Everyone should know git clone
, there are no tricks. I took a look at my java
openjdk version "17.0.8.1" 2023-08-24
; mvn
, oh, this virtual machine I Even mvn is not installed…directly sudo apt install maven
[Pit 1]
We will fill it in later; then the tools will be complete, and such a java project is usually mvn clean package
.
Change database
The modularization of the “Ruoyi” project is actually not friendly, such as strong binding mysql
. Then find application.yml
and take a stroll to see where the configuration database is. I only see that pagehelper.helperDialect
needs to be corrected to sqlite
; in addition, the location of ruoyi.profile
can be updated.
The application-druid.yml
next to it uses druid
. Most of the database settings are here. Comment out
## Main database data source #master: # url: jdbc:mysql://localhost:3306/ry?useUnicode=true & amp;characterEncoding=utf8 & amp;zeroDateTimeBehavior=convertToNull & amp;useSSL=true & amp;serverTimezone=GMT+8 # username: root # password: password # From database data source #slave: # # Switch from data source/default off # enabled: false #url: # username: # password:
Then we replace spring.datasource.driverClassName
with sqlite’s org.sqlite.JDBC
; then spring.datasource.url
can set a default first For example, jdbc:sqlite:test.db
can be changed later by -Dspring.datasource.url
. spring.datasource.druid.validationQuery
needs to be changed later, for example, SELECT test FROM DUAL
; because SELECT 1 FROM DUAL
no matter what , sqlite will not produce results.
After changing the driver class, of course we need to declare the dependency. Go to pom.xml
under ruoyi-admin
and comment out the dependency of Mysql driver package
and replace it with
<dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> <version>3.16.1</version> </dependency>
【Pit 2】
The database driver has been changed. We can also see that “Ruoyi” has a sql
folder with two files quartz.sql
and ry_
; these two are also strongly bound to mysql
. Need to be updated manually. In fact, it is not difficult to convert to sqlite
.
- All
sys_date()
are converted toCURRENT_TIMESTAMP
, - All auto_increament, if it is bigint or int, all become
integer primary key autoincrement
, - If mysql has a separate
primary key(...)
and comments it out later, it will be fine. engine=innodb auto_increment=100
Comment out all mysql proprietary guys- Then put all mysql’s
comment
into--
and then comment them out, paying attention to the missing commas. - Also comment out the place where mysql
key
exists, pull it out and convert it intodrop index if exists
; create on
(
); - Finally add a table
DUAL
to ensure validation pass:create table DUAL (test integer); insert into DUAL (test) values (1);
After modification, you can import sql statements in
sqlite3
.read
.Run
The sqlite configuration has almost been changed. Let’s try running it first.
[Pit 1]mvn clean package
, and then an error was reported[ERROR] Error executing Maven. [ERROR] java.lang.IllegalStateException: Unable to load cache item [ERROR] Caused by: Unable to load cache item [ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
This is a problem with the maven version. What does apt get install for me by default?
mvn --version
->3.6.3
-_-///
The latest maven 3.9 will not report an error.mvn clean package
You can getruoyi-admin.jar
in thetarget
folder ofruoyi-admin
, and you can run it now…
java -Dserver.port=9999 -Dspring.datasource.url=jdbc:sqlite:/path/to/test.db -jar ruoyi-admin.jar
【Pit 2】An error message that I can’t understand is reported again.Unparseable date: "xxxx-yy-zz 00:00:00" does not match (\p{Nd} + + )\Q-\E(\p{Nd} + + )\Q-\E( \p{Nd} + + )\Q \E(\p{Nd} + + )\Q:\E(\p{Nd} + + )\Q:\E(\p{Nd} + + )\ Q.\E(\p{Nd} + + )
After taking a look, the sqlite driver cannot parse the timestamp generated by sqlite, which is a bit of a joke.
Rely on the official github to solve it ref: https://github.com/xerial/sqlite-jdbc/issues/88xerial commented on Jul 1, 2021
I’ll release 3.36.0.1 today.Go to https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc to see the latest version,
3.43.2.2
Started successfully!
After logging in, I found that an error was reported; oh, I forgot about mybatis used by “Ruoyi”, there must be a bunch of sql embedded in xml.
- ./ruoyi-generator/src/main/resources/mapper/generator/
- ./ruoyi-generator/src/main/resources/vm/sql
- ./ruoyi-quartz/src/main/resources/mapper/quartz
- ./ruoyi-system/src/main/resources/mapper/system
I won’t go into details one by one. It’s just a rewrite of SQL, mysql -> sqlite.
After finishing it, I found an incomplete repo that someone had already done.
Here is the final summary
https://gitee.com/shuizhimeng/ruo-yi-fast-sqlite/blob/master/sql/Update recordIn this way, “Ruoyi” will start running. It hasn’t been long since I typed this article…
Of course the same goes for replacing those oracle DB and postgresql…
Later we will add the microservice version of “Ruoyi”, which consists of multiplenacos
and some cloud-related components. - Finally add a table