[Notes] Ruoyi: Use sqlite3 to do whatever you want

“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_ .sql; these two are also strongly bound to mysql. Need to be updated manually. In fact, it is not difficult to convert to sqlite.