تقدم هذه المقالة بشكل أساسي بناء وتشغيل وتغليف مشاريع Maven متعددة الوحدات. تتم مشاركتها معك. التفاصيل كما يلي:
الأدوات التي يستخدمها المشروع:
دليل المشروع:
1. إنشاء مشروع Springboot باستخدام IDEA: ملف -> جديد -> مشروع اسم المشروع هو Springboot -Multi
2. حذف دليل SRC في المشروع وتغيير طريقة التغليف للمشروع في pom.xml إلى POM ، على النحو التالي:
<roughid> com.example </rougiD> <StifactId> Springboot-Multi </shintifactid> <soph> 0.0.1-snapshot </version> <!-تغيير إلى POM-> <cplaging> pom </plaging>
3. قم بإنشاء عرض فرعي لمشروع Springboot-Multi ، انقر بزر الماوس الأيمن على المشروع ، وحدد: جديد-> وحدة.
4. بعد إنشاء أربع عروض فرعية ، قم بحذف جميع الملفات تحت SRC/MAIN/JAVA و SRC/MAY/JAVA في الجهاز الفرعي (تخطي هذا إذا لم يتم تخطي أي ملفات) ، واحتفظ فقط بفئة بدء تشغيل التطبيق الرئيسية في وحدة الويب الفرعية.
5. المشروع الرئيسي pom.xml (لاحظ ما إذا كانت العلامة <الوحدات> تحدد وحدة فرعية)
<Domodversion> 4.0.0 </modelversion> <rougiD> com.example </rougiD> <ArtifactId> Springboot-Multi </stifactid> <sored> 0.0.1-snapshot </version> <!-تغيير إلى POM-> <Packaging> pom </name> springboot-multi </description> <Module> web </somule> <sodule> خدمة </module> <module> dao </somule> <الوحدة النمطية> الكيان </module> </modules> <partiD> <roupiD> org.springframework. <!-Lookup Parent from ropository-> </paret> <properties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> <project.reporting.outputencoding> utf-8 </project.reporting.utputencoding> <ependencies> <Rependency> <roupiD> org.springframework.boot </rougiD> <StifactId> Spring-Boot-Starter-Web </stifactid> </reperence> </sependencies> <!- <StifactId> maven-compiler-plugin </stifactid> <الإصدار> 3.1 </version> <socenturation> <source> $ {java.version} </source> <target> $ {java.version} </target> </configuration> <StifactId> maven-surefire-plugin </shintifactid> <الإصدار> 2.19.1 </version> <simpturation> <skiptests> true </skiptests> <!-اختبارات الوحدة إيقاف التشغيل بشكل افتراضي-> </configuration> </sultcin> </plugins> </build> 6. Web Submodule Pom.xml (يعتمد على الخدمة ، DAO ، الجهاز الفرعي للكيان)
<DodelVersion> 4.0.0 </modelversion> <rougiD> com.example </rougiD> <ArtifactId> web </shintifactid> <sored> 0.0.1-snapshot </version> <backaging> jar </packaging> <name> web </same> <specord> Demo Project </descrip <StifactId> Springboot-multi </shintifactid> <sored> 0.0.1-snapshot </version> <siredPath> ../ pom.xml </speratepath> </parent> <ependencies> <redence> <roupensid> com.example </groupid> <Rependency> <roupency> com.example </groupId> <StifactId> dao </artifactId> <sophy> 0.0.1-snapshot </version> </sependency> <redence> <roupiD> com.example </groupiD> <sringActid> كيان attifactid> يتطلب بداية فريدة من نوعها-> <TUNDING> <PLIDINS> <PLUDIN> <VERLOGID> org.springframework.boot </rougiD> <StifactId> spring-boot-maven-plugin </suntifactid> <configuration> <!-حدد الفئة الرئيسية باعتبارها الإدخال الفريد العالمي-> mainclass> com </ispification> <evelopmentions> <evelop> <irod> <diro> repackage </soph> <!-يمكنك حزم جميع التبعيات في حزمة JAR التي تم إنشاؤها-> </execution> </exراضية> </plugin> </plugins> </build>
7. خدمة Submodule Pom.xml (يعتمد على عروض DAO والكيان الفرعية)
<DodelVersion> 4.0.0 </modelversion> <rougiD> com.example </groupId> <ArtifactId> خدمة </artifactid> <sophy> 0.0.1-snapshot </version> <backaging> jar </packaging> service </name> <Description> Demo Project </descrip <StifactId> Springboot-multi </shintifactid> <soph> 0.0.1-snapshot </version> <siredPath> ../ pom.xml </speratepath> </parent> <ependencies> <redency> <roupencid> com.example </rougeid> dao </spensid> <Rependency> <roupend> com.example </rougiD> <StifactId> الكيان </artifactid> <soph> 0.0.1-snapshot </version> </sependency> </sependenc
8. Dao Submodule Pom.xml (تعتمد على الجهاز الفرعي للكيان)
<DodelVersion> 4.0.0 </modelversion> <rougiD> com.example </groupId> <ArtifactId> dao </stifactid> <sored> 0.0.1-snapshot </version> <backaging> jar </packaging> <same> dao </ame> <StifactId> Springboot-multi </shintifactid> <soph> 0.0.1-snapshot </version> <siredPath> ../ pom.xml </speripath> </ulart> <ependencies> <sperency> <roupeD> com.example </groupiD> </artifactid> </التبعيات>
9. كيان فرعي
<Dodeversion> 4.0.0 </domedversion> <rougiD> com.example </rougiD> <intifactid> الكيان </artifactid> <الإصدار> 0.0.1-snapshot </version> <packaging> جرة </packaging> <name> الكيان </name> <Description> Demo Project </description> <StifactId> Springboot-Multi </shintifactid> <sophy> 0.0.1-snapshot </splement> <siredPath> ../ pom.xml </siredpath> </paret>
10. ما تحتاج إلى الانتباه إليه في ملف pom.xml هو:
11. فئة بدء تشغيل التطبيق للواقع الفرعي:
RestControllerSpringBootApplication الفئة العامة webapplication {public static void main (string [] args) {springapplication.run (webapplication.class ، args) ؛ } @requestmapping (value = "/test" ، method = requestMethod.get) test string public test () {return "test success" ؛ }}12. قم بتنفيذ الطريقة الرئيسية لبدء المشروع ، وزيارة LocalHost: 8080/Test ، ويبدو أن الصفحة التالية تشير إلى أن المشروع قد تم إنشاؤه بنجاح:
13. أمر تعبئة المشروع: حزمة MVN Clean أو استخدم الواجهة الرسومية لشريط الأدوات على اليمين إلى الحزمة:
14. سجل نجاح التغليف:
ما سبق هو كل محتوى هذه المقالة. آمل أن يكون ذلك مفيدًا لتعلم الجميع وآمل أن يدعم الجميع wulin.com أكثر.