简体   繁体   English

如何在春季创建多Web模块应用程序?

[英]How to create multi web module application in spring?

I'm trying to create a multi-web module application in spring. 我正在尝试在春季创建一个多Web模块应用程序。 Below is the project structure. 以下是项目结构。

+-- Parent
|---- Java (Which has the controller, models and views)
|---- resources
|---- webapp
|------ web.xml
|------ jsp 
+-- Purchase (Submodule 1)
|---- Java (Which has the controller, models and views)
|---- resources
|---- webapp
|------ web.xml
|------ jsp 
+-- Sales (Submodule 2)
|---- Java (Which has the controller, models and views)
|---- resources
|---- webapp
|------ web.xml
|------ jsp 

I want to build purchase (submodule 1) and sales (submodule2) as separate jar or war and add it to the lib of parent and run the application and access the controllers as 我想将购买(子模块1)和销售(子模块2)构建为单独的jar或war,并将其添加到父级的lib中,然后运行应用程序并以以下方式访问控制器

localhost:8080/parent
localhost:8080/purchase
localhost:8080/sales

Could someone let me know the approach that available in spring to achieve the thing it would be helpful 有人可以让我知道春季可以用来实现目标的方法吗?

Thanks in advance! 提前致谢!

Regarding the structure and responsibility for each project, I would suggest modeling it like 关于每个项目的结构和职责,我建议像

parent 父母

  • web-service (only controllers and views, no business logic, delegates to sales and purchase for business logic) Web服务 (仅控制器和视图,无业务逻辑,业务逻辑的销售和采购委托)
  • sales (sales business logic - no controllers and views) 销售 (销售业务逻辑-无控制器和视图)
  • purchase (purchase business logic - no controllers and views) 购买 (购买业务逻辑-没有控制器和视图)

You might have to add additional modules for utils / persistence / entities , depending on your specific requirements. 您可能需要为utils / persistence / entity添加其他模块,具体取决于您的特定要求。

Regarding building per se, there are a couple of options here, the most widely used bing maven and gradle . 关于建筑物本身,这里有两个选择,使用最广泛的bing mavengradle Both of them support structuring an application in parent - child modules. 它们都支持在父子模块中构造应用程序。 Both of them support adding dependencies for a child module in another child module (so you are able to add dependencies on sales and purchase in web-service ). 它们都支持在另一个子模块中添加子模块的依赖关系(因此,您可以在Web服务中添加对销售购买的依赖关系)。

Both maven and gradle will take care to build all needed dependencies for a given module before building that module (so it is guaranteed that sales and purchase will be built before web-service ). maven和gradle都将在构建模块之前小心地为给定模块构建所有必需的依赖项(因此可以确保在Web服务之前构建销售购买 )。 Both maven and gradle will fail the build if they are not able to satisfy a dependency. 如果maven和gradle无法满足依赖关系,它们都将使构建失败。

I think it is about the which web server you use. 我认为这与您使用的Web服务器有关。 Just set them different context roots. 只需为它们设置不同的上下文根。 You should take a look at this answer https://stackoverflow.com/a/32008624/7541163 您应该看看这个答案https://stackoverflow.com/a/32008624/7541163

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

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