※当サイトの記事には、広告・プロモーションが含まれます。

Spring Web MVCがServletを利用してるの図解してあげれば良い気はするけど...

www.itmedia.co.jp

 レビューの流れはこうだ。Bardとの会話から無作為に抽出されたサンプルを、人間のレビュアーが確認。品質が低くないか、不正確でないか、有害でないかなど品質を判断する。その後、評価担当者が、複数のポリシーに照らしてより品質の高い回答を提案するという。

AI「Bard」は位置情報を常に取得 会話を「人間がレビューする可能性」も Googleが理由説明 - ITmedia NEWS

⇧ 抽出するのはどれぐらいのサンプルを想定してるのかしら?

Spring Web MVCServletを利用してるの図解してあげれば良い気はするけど...

何か、初学者にJSP/Servletを教えるのは効率的ではないって話があって、概ね、その通りだと思うんだけど、どちらかと言うと、フレームワークで隠蔽されてるのだから、フレームワーク側でどのようにServletが利用されているのかを教えてあげるべきだと思うんよね...

ちなみに、Spring FrameworkのSpring Web MVCってライブラリだと、

github.com

GitHubで公開しているソースコードを見た限り、

https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java

/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.web.servlet;

import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.PropertyValues;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.ServletContextResourceLoader;
import org.springframework.web.context.support.StandardServletEnvironment;

/**
 * Simple extension of {@link jakarta.servlet.http.HttpServlet} which treats
 * its config parameters ({@code init-param} entries within the
 * {@code servlet} tag in {@code web.xml}) as bean properties.
 *
 * <p>A handy superclass for any type of servlet. Type conversion of config
 * parameters is automatic, with the corresponding setter method getting
 * invoked with the converted value. It is also possible for subclasses to
 * specify required properties. Parameters without matching bean property
 * setter will simply be ignored.
 *
 * <p>This servlet leaves request handling to subclasses, inheriting the default
 * behavior of HttpServlet ({@code doGet}, {@code doPost}, etc).
 *
 * <p>This generic servlet base class has no dependency on the Spring
 * {@link org.springframework.context.ApplicationContext} concept. Simple
 * servlets usually don't load their own context but rather access service
 * beans from the Spring root application context, accessible via the
 * filter's {@link #getServletContext() ServletContext} (see
 * {@link org.springframework.web.context.support.WebApplicationContextUtils}).
 *
 * <p>The {@link FrameworkServlet} class is a more specific servlet base
 * class which loads its own application context. FrameworkServlet serves
 * as direct base class of Spring's full-fledged {@link DispatcherServlet}.
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @see #addRequiredProperty
 * @see #initServletBean
 * @see #doGet
 * @see #doPost
 */
@SuppressWarnings("serial")
public abstract class HttpServletBean extends HttpServlet implements EnvironmentCapable, EnvironmentAware {
...省略
}
 

⇧ とあるように、Spring Web MVC(おそらく、Spring Frameworkを使ったアプリケーションであれば、何だかんだで利用していると思うけど)を利用している場合、必然的に間接的とは言えServletを利用していますと。

docs.spring.io

Spring MVC, as many other web frameworks, is designed around the front controller pattern where a central Servlet, the DispatcherServlet, provides a shared algorithm for request processing, while actual work is performed by configurable delegate components. This model is flexible and supports diverse workflows.

https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-servlet.html

⇧ という説明になっており、Servletを使ってるってことかと。

公式だとSpring Web MVCServletがどのように機能してるのかについて最新の図解が見当たらないんだけど、

qiita.com

qiita.com

⇧ 上記サイト様が図解してくれている。

なので、どちらかと言うと、初学者には、JSP/Servletはサラッと説明して、実際にServletフレームワークの中でどのように利用されてるのかを図解で説明してあげた方が良い気がする。

公式のドキュメントでもっとフレームワークアーキテクチャ的な部分の図解を公開してくれれば、効率的なんですけどね...

如何せん、公式のドキュメントの図解が、

docs.spring.io

⇧ バージョン3.2が上位検索でヒットする哀しさよ...

最新バージョンのドキュメントだと、

⇧ Requestの全体フローの図解が見当たらんのよね...

By the way、Spring BootでSpring Web MVCを使う場合でも、Spring Bootの組み込みのアプリケーションサーバーってTomcatだった気がするんで、Servlet使ってるんだと思うけど。

ちなみに、Spring WebFluxの説明だと、

docs.spring.io

⇧ Spring Web MVCは、Servlet使ってるって説明になってますね。まぁ、上記のドキュメントもバージョン5.0.0.M5のなので、最新でどうなってるか分からんのだけど...

とりあえず、公式のドキュメントでは、図解をもっと増やして欲しいし、最新のドキュメントでも継続して図解を載せて欲しいんよね...

あと、検索した時に見つかりやすいようにして欲しいかな、ドキュメントで各ライブラリ毎にOverviewのページを用意して全体像の図解を載せて欲しい...

そう言えば、Spring FrameworkGitHubで公開してるビルドツールがGradleになってたんだけど、

spring.io

We made a fairly significant change to Spring Boot in 2.3.0.M1. It was the first release of the project to be built with Gradle rather than Maven.

https://spring.io/blog/2020/06/08/migrating-spring-boot-s-build-to-gradle

For example, Spring Framework has been built with Gradle since 3.2.0.M1 in 2012, whereas Spring Boot began a year later and Spring Cloud shortly after that, both with Maven-based builds. Unlike Spring Boot, Spring Cloud has no plans to switch as Maven continues to meet their needs. In short, if you take only one thing from this blog post it’s that you should choose whatever tool best meets your project’s needs.

https://spring.io/blog/2020/06/08/migrating-spring-boot-s-build-to-gradle

⇧ 2020年6月20日のブログで、Spring Boot in 2.3.0.M1 で、MavenからGradleに切り替えたって話題が出てたけど、Spring Frameworkに至っては、3.2.0.M1ってバージョンからGradleでビルドされてたらしく、2012年頃だったみたい...

そして、Wikipediaさんによると、

⇧ 何故か、Servletの説明ページの図解で、JSPに焦点を当ててるという...

とりあえず、公式のドキュメントだと、

docs.spring.io

Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, "Spring Web MVC," comes from the name of its source module (spring-webmvc), but it is more commonly known as "Spring MVC".

https://docs.spring.io/spring-framework/reference/web/webmvc.html

⇧ ってことで、Spring Web MVCServlet APIに基づいているってことではある模様。

フロントエンドとサーバーサイド(Java)であれば、Spring Web MVCでHTTP通信ってパターンが多いとは思うんだけど、サーバーサイド(Java)と対外システムの通信ってなった場合に、HTTP通信するのに、Spring Web MVC以外を使う必要があるってのがややこしいところでもあるんだけど...

そもそも、HTTP通信を使わないってケースもあるから何とも...

正しい情報かどうかが分からないのだけど、

mossgreen.github.io

⇧ 上図のような図解を公式のドキュメントで載せて欲しいんよね...ただ、Servlet然りSpring Framework然り、アプリケーションサーバーじゃないと動かない気はするから、上図の信憑性は心許ない...

フロントエンドからのリクエストがサーバーサイド(Java)で、どういう流れで処理されるのかイメージが掴めた方が初学者には取っ付き易い気がするかなぁ。

Spring Bootが設定周りを良しなにしてくれちゃってる部分がブラックボックス化してるのもなかなか辛いけども、何かよく分からんけど動いちゃうってのがモヤるし、動かんくなった時にどこが悪いかの原因特定に時間取られるんよね...

Servlet云々の前に、問題が起きた際の原因の特定の仕方を研修で教えてあげるのが一番な気がしますかね...

問題の切り分けをするためにも、仕組みは分かっていた方が良いと思うし、逆にお作法とかおまじないって言ったり、本質的ではないと言ったり、時間が足りないのでと言ったりして説明を避けて濁すような研修は講師の人のやる気が疑われる...

もし教える側自身が理解できてなくて、ハッキリ、私には分かりません、って言ってくれるのであれば誠意はあると思うけど...

毎度モヤモヤ感が半端ない...

今回はこのへんで。