English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SpringBoot Starter Web

لدي spring-boot-starter-web功能 مهمتان:

التوافق مع تطوير الويب الإعداد التلقائي

إذا كنت ترغب في تطوير تطبيق ويب، فعليك إضافة التبعيات التالية إلى ملف pom.xml:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>

برنامج بدء Spring Web يستخدم Spring MVC،REST وTomcat كخادم مضمن افتراضي. يمكن الحصول بشكل متبادل على جميع التبعيات المتعلقة بتطوير الويب من خلال依赖ية spring-boot-starter-web. كما يقلل من عدد بنود التبعيات البنائية.

org.springframework.boot: spring-boot-starter org.springframework.boot: spring-boot-starter-tomcat org.springframework.boot: spring-boot-starter-validation com.fasterxml.jackson.core: jackson-databind org.springframework: spring-web org.springframework: spring-webmvc

بالتقديم الافتراضي، يحتوي spring-boot-starter-web على التبعيات التالية لمسار Tomcat:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.0.0.RELEASE</version>
<scope>compile</scope>
</dependency>

spring-boot-starter-web يضمن التالي لتنظيم تطوير Web:

Servlet المخطط صفحات الأخطاء لإدارة الاعتماد الثابتة باستخدام Web JAR مكتبة servlet مضمنة

خادم Spring Boot المضمن Web

كل تطبيق Spring Boot يحتوي على خادم مضمن. يتم تضمين الخادم المضمن كجزء من التطبيق القابل للنشر. منافع الخادم المضمن هو أننا لسنا بحاجة إلى تثبيت الخادم في البيئة. باستخدام Spring Boot، الخادم المضمن الافتراضي هو Tomcat Spring Boot يدعم أيضًا خادمين مضمنين آخرين:

خادم Jetty خادم Undertow

باستخدام خادم Web مضمن آخر

لل مكتبة servletالتطبيق، spring-boot-starter-web من خلال الإضافة spring-boot-starter-tomcat للإضافة Tomcat ،لكن يمكننا استخدام spring-boot-starter-jetty أو spring -boot-starter-undertow

لل المفاعلالتطبيق، spring-boot-starter-webflux بما في ذلك بما في ذلك spring-boot-starter-reactor-netty لتحقيق Reactor Netty ،لكن يمكننا استخدام spring-boot-starter-tomcat،spring-boot-starter-jetty،

خادم Jetty

يدعم Spring Boot أيضًا ما يُدعى بـ خادم Jetty. إنه خادم HTTP ومحتويات Servlet، يقدم وظائف تقديم المحتويات الساكنة والديناميكية.

إذا كنت ترغب في إضافة خادم Jetty إلى التطبيق، فإنه يجب عليك إضافة spring-boot-starter-jetty التابعيات.

تذكر: . عند استخدام خادم Jetty في التطبيق، تأكد من أنك تستخدم يحذف الخادم الافتراضي Tomcat spring-boot-starter-web . يضمن تجنب الصراع بين الخوادم.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

يمكننا أيضًا استخدام application.properties يأتي من ملف مخصص لسلوك خادم Jetty.

Undertow Server

يقدم Spring Boot خيارًا آخر يُدعى Undertow يعد الخادم. وهو أيضًا خادم Web مدمج مثل Jetty. مكتوب بلغة Java، مدارة وممول من قبل JBoss. من بين مزايا خادم Undertow الرئيسية:

دعم HTTP/2 دعم تحديث HTTP دعم Websocket يقدم دعمًا لتقنية Servlet 4.0 مرن قابل للإدراج

تذكر: : عند استخدام خادم Undertow في التطبيق، تأكد من أنك تستخدم spring-boot-starterيحذف الخادم الافتراضي Tomcat -web.يضمن تجنب الصراع بين الخوادم.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

يمكننا أيضًا استخدام application.properties يأتي من ملف مخصص لسلوك خادم Undertow.

spring-boot-starter-web مقابل spring-boot-starter-tomcat

spring-boot-starter-web يحتوي على التبعيات الـweb الـspring، بما في ذلك spring-boot-starter-tomcat. يحتوي spring-boot-starter-web على ما يلي:

spring-boot-starter jackson spring-core spring-mvc spring-boot-starter-tomcat

spring-boot-starter-tomcat يحتوي على جميع المحتويات المتعلقة بتطبيق Tomcat الخادم.

core el logging websocket

starter-tomcatيحتوي على التبعيات التالية:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.23</version>
 <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>

يمكننا أيضًا استخدام spring-mvc بدلاً من استخدام Tomcat Server المدمج. إذا أردنا القيام بذلك، يجب أن نستخدم  استبعاد Tomcat Server كما هو موضح في الكود التالي.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>