We want to find a ready-made open source background management framework from the Internet. After several comparisons, we selected Ruoyi, the technology stack is very close to our current use, MIT license, quite loose, completely open source and free. Plus, the functionality looks great, so vote for her.
I downloaded the multi-module version. Multiple modules have many benefits, which are conducive to separate development, and the code also has a certain degree of isolation. In applying the framework, it is also natural to implement the idea that the new business management module should be separated from the original module. But then you have a spring Boot project with multiple WEB modules. How can multiple WEB modules coexist? Or, how does it all fit together? Or, how can my newly developed WEB module directly use existing work in the framework?
If it’s a non-Web module, this is easy to understand. It’s nothing more than an import, referencing its functions, methods, constructing instances of it, and so on in your code. But what about the WEB? There are controllers, there are templates, there are static files, CSS, JS, etc., how to reference these?
The answer is quotable. The way to do this is in the Application @import web module.class.
In this example, the code structure:
Ruoyi-admin is an inherent WEB module of the Ruoyi framework. The whole framework provides user management, menu management, dictionary, log and other functions, so we only need to add the business part of the management function. This new functionality is housed in “Business”, which is also a Web module. Business code structure:
This is a typical Spring Boot project structure.
Within this new module, reference the framework’s native WEB module: ruoyi-admin.
First, modify business’s pom.xml to add a reference to ruoyi-admin:
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-admin</artifactId>
<version>4.1.0</version>
<scope>compile</scope>
</dependency>
Copy the code
2. Modify the startup program of Business, BusinessApplication
/** * start the program **@author chenqu
*/
//RuoYiApplication is the ruoyi-admin launcher
@Import(RuoYiApplication.class)/ / <! ----------- is the sentence
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class BusinessApplication extends SpringBootServletInitializer {
public static void main(String[] args){
SpringApplication.run(BusinessApplication.class, args);
System.out.println("============= Service management background started successfully =============\n");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
returnapplication.sources(BusinessApplication.class); }}Copy the code
When you start BusinessApplication this way, you have both the existing module and the new module. After startup, Business’s resources are combined with Ruoyi-Admin’s resources (you can see that resources are really treated as resource files and should be compiled into jar packages). Therefore, if business needs to add resource files, it should avoid the same name as ruoyi-admin.
This way, basically do not change the framework inherent code, only in the new module to find a way, in line with the open and closed principle, the code has a very clear partition, I am very satisfied.