简体   繁体   English

Spring Boot测试:每个模块都有Application类是一个好主意吗?

[英]Spring Boot Test: Is it a good idea to have Application class per module?

My project looks like: 我的项目看起来像:

myProject/
         /persistence/pom.xml
         /persistence/src/main/java/PersistenceApplication.java
         /persistence/src/main/java/**.java

         /business/pom.xml
         /business/src/main/java/BusinessApplication.java
         /business/src/main/java/**.java

         /api/pom.xml
         /api/src/main/java/ApiApplication.java
         /api/src/main/java/**.java  

api depends on business and business depends on persistence module. api取决于businessbusiness取决于persistence模块。 When run in production, ApiApplication will be the main class. 在生产中运行时, ApiApplication将是主要类。

However, when running tests, I feel a requirement to add PeristenceApplication and BusinessApplication just in order to run Spring tests annotated with @SpringBootTest . 但是,在运行测试时,我觉得有必要添加PeristenceApplicationBusinessApplication以便运行以@SpringBootTest注释的Spring测试。

Is it really a requirement? 真的需要吗? I do not know a lot about Spring-Boot and would love to know what is the recommendation here? 我对Spring-Boot了解不多,很想知道这里的建议是什么?

How can I test my modules using @SpringBootTest but without requiring *Application.java in persistence and business module? 如何在persistencebusiness模块中使用@SpringBootTest来测试模块,而不需要*Application.java

Thanks 谢谢

I believe that decoupling by layer (horizontally) is outdated approach from decade ago. 我认为,分层分离(水平)是十年前的过时方法。 I believe that project shouldn't be structured "module by layer" nor "package by layer". 我认为该项目不应“按模块”或“按包”构建。

It should be structured "package by feature" or "module by feature" or "microservice by feature" (vertical decoupling). 它的结构应为“按功能打包”或“按功能模块”或“按功能微服务”(垂直解耦)。

With vertical decoupling, you would cover within integration test certain feature in one package/module/microservice and your consideration would be naturally gone. 使用垂直解耦,您将在集成测试中涵盖一个包/模块/微服务中的某些功能,因此您的考虑自然会消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM