SpringBoot官方笔记3核心

本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 SpringApplication By default, INFO logging messages are shown, including some relevant startup details, such as the user that launched the application. Lazy Initialization When lazy initialization is enabled, beans are created as they are needed rather than during application startup. spring.main.lazy-initialization=true @Lazy(false) annotation:disable lazy initialization for certain beans Customizing the Banner adding a banner.txt file to your classpath or by setting the spring.banner.location property to the location of such a file. If the file has an encoding other than UTF-8, you can set spring.banner.charset. ...

JavaWeb开发基础Servlet请求分发与重定向

本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 请求分发 Servlet的RequestDispatcher接口定义: package javax.servlet; import java.io.IOException; public interface RequestDispatcher { String FORWARD_REQUEST_URI = "javax.servlet.forward.request_uri"; String FORWARD_CONTEXT_PATH = "javax.servlet.forward.context_path"; String FORWARD_PATH_INFO = "javax.servlet.forward.path_info"; String FORWARD_SERVLET_PATH = "javax.servlet.forward.servlet_path"; String FORWARD_QUERY_STRING = "javax.servlet.forward.query_string"; String INCLUDE_REQUEST_URI = "javax.servlet.include.request_uri"; String INCLUDE_CONTEXT_PATH = "javax.servlet.include.context_path"; String INCLUDE_PATH_INFO = "javax.servlet.include.path_info"; String INCLUDE_SERVLET_PATH = "javax.servlet.include.servlet_path"; String INCLUDE_QUERY_STRING = "javax.servlet.include.query_string"; String ERROR_EXCEPTION = "javax.servlet.error.exception"; String ERROR_EXCEPTION_TYPE = "javax.servlet.error.exception_type"; String ERROR_MESSAGE = "javax.servlet.error.message"; String ERROR_REQUEST_URI = "javax.servlet.error.request_uri"; String ERROR_SERVLET_NAME = "javax.servlet.error.servlet_name"; String ERROR_STATUS_CODE = "javax.servlet.error.status_code"; void forward(ServletRequest var1, ServletResponse var2) throws ServletException, IOException; void include(ServletRequest var1, ServletResponse var2) throws ServletException, IOException; } 它有2个方法,forward和include: ...

Java官方笔记2面向对象编程基本概念

本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 对象Object 对象有2个特征:状态state和行为behavior。我们可以用真实世界的对象来做类比,这样有助于理解面向对象编程,比如狗的状态(名字、颜色、品种)和行为(叫、抓、摇尾巴),自行车的状态(当前档位、当前踏板节奏、当前速度)和行为(切换档位、切换踏板节奏、踩刹车)。 软件对象也是由状态和行为组成: 状态,在软件对象中,叫做字段fields,或变量variables。 行为,在软件对象中,叫做方法methods,或函数functions。 所谓的数据封装data encapsulation,就是字段只在内部,不对外暴露,仅由方法进行操作,对象与对象之间通过方法来相互访问。 Java是纯粹的面向对象编程语言。 类Class 类,可以视为对象的模版,基于类来创造出同一类对象。 比如自行车的类: class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear); } } 类也是有2个特征:字段和方法。比如Bicycle类有字段cadence、speed、gear和方法changeCadence()、changeGear()、speedUp()等。 ...

SpringBoot官方笔记2使用

本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 Build Systems 选择Maven or Gradle,而不要Ant(not particularly well supported) In practice, you do not need to provide a version for any of these dependencies (spring-boot-dependencies) in your build configuration, as Spring Boot manages that for you. When you upgrade Spring Boot itself, these dependencies are upgraded as well in a consistent way. Each release of Spring Boot is associated with a base version of the Spring Framework. Starters are a set of convenient dependency descriptors that you can include in your application. ...

JavaWeb开发基础Servlet生命周期与工作原理

本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 Servlet生命周期 Servlet的生命周期由Servlet容器(如Tomcat、Jetty等)管理,主要包括以下5个阶段: 加载Servlet类 创建Servlet实例 调用init方法 调用service方法 调用destroy方法 加载(Loading): 当Servlet容器启动或第一次接收到对某个Servlet的请求时,它会加载Servlet类 这个过程只发生一次,除非Servlet被卸载或容器重新启动 实例化(Instantiation): 在加载Servlet类之后,容器会创建一个Servlet实例 这个实例化过程也是一次性的,除非Servlet被卸载或容器重新启动 初始化(Initialization): 容器调用Servlet实例的init()方法进行初始化 init()方法只被调用一次,用于执行一次性的初始化任务,如读取配置参数、初始化资源等 你可以重写init()方法以执行自定义的初始化逻辑 public void init(ServletConfig config) 请求处理(Request Handling): 每当有请求到达时,容器会调用Servlet的service()方法来处理请求 service()方法根据请求的类型(如GET、POST等)调用相应的处理方法(如doGet()、doPost()等) public void service(ServletRequest request, ServletResponse response) 销毁(Destruction): 当容器决定卸载Servlet(如容器关闭或Servlet被重新加载)时,它会调用Servlet的destroy()方法 destroy()方法用于执行清理任务,如关闭资源、保存状态等 destroy()方法只被调用一次 public void destroy() Servlet重新加载 Servlet被重新加载通常发生在以下几种情况下: Servlet类文件被修改: 如果在开发过程中修改了Servlet类文件,Servlet容器可能会检测到这些更改并重新加载Servlet 这通常发生在开发环境中,生产环境中一般不会自动重新加载 容器配置发生变化: 如果修改了Servlet容器的配置文件(如web.xml),容器可能会重新加载相关的Servlet 容器重启: 当Servlet容器重启时,所有的Servlet都会被重新加载 手动重新加载: 某些Servlet容器提供了手动重新加载Servlet的功能,通常通过管理控制台或命令行工具 当Servlet被重新加载时,Servlet容器会执行以下步骤: 销毁现有的Servlet实例: 容器调用现有Servlet实例的destroy()方法,执行清理任务 释放资源,如关闭数据库连接、释放文件句柄等 卸载Servlet类: 容器卸载现有的Servlet类,释放类加载器持有的资源 重新加载Servlet类: 容器重新加载Servlet类文件,创建新的类加载器实例 实例化新的Servlet对象: 容器创建新的Servlet实例 初始化新的Servlet实例: 容器调用新的Servlet实例的init()方法进行初始化 Servlet代码示例 有3种方式使用Servlet: ①实现Servlet接口 import java.io.*; import javax.servlet.*; public class First implements Servlet { ServletConfig config = null; public void init(ServletConfig config) { this.config = config; System.out.println("servlet is initialized"); } public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.print("<html><body>"); out.print("<b>hello simple servlet</b>"); out.print("</body></html>"); } public void destroy() { System.out.println("servlet is destroyed"); } public ServletConfig getServletConfig() { return config; } public String getServletInfo() { return "copyright 2007-1010"; } } ②继承GenericServlet类 ...

Java官方笔记1编写运行Java程序

你可能已经迫不及待想安装Java,写个Java程序跑起来了。但是在这之前,有些概念需要提前了解,因为Java跟C、C++和Python都有点不一样。

SpringBoot官方笔记1入门

Spring Boot helps you to create stand-alone, production-grade Spring-based applications that you can run. Most Spring Boot applications need very little Spring configuration.

Dockerfile文件万字全面解析

Dockerfile是一个文本文件,包含一些Docker指令。执行docker build,Docker就会执行Dockerfile里面的指令,来自动创建镜像。

2026-01-03 · 14 分钟 · 2820 字 · 测试开发刚哥 · Java生态 · #Golang

JavaWeb开发基础ServletAPI

本书作者:测试开发刚哥,文章版权归个人所有,未经授权请勿转载。 Servlet版本 Oracle将Java EE(Java SE还自己保留)交给开源组织,Eclipse基金会接手。但Oracle不允许开源组织使用Java名号,所以Jakarta EE名称于2018.02.26应运而生。 正是因为组织变化,Servlet被割裂为了2个版本,javax.servlet和jakarta.servlet。 javax.servlet已经停止维护,但它仍然是一个非常有用和重要的技术,特别是在许多现有项目中,学习和使用它将为你提供坚实的Web开发基础。 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> 如果希望使用Jakarta EE 9或更高版本的Servlet API,则需要切换到javax.servlet。 <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency> 本文将基于javax.servlet来介绍Servlet,从Usages来看,它仍然是使用最广泛的。 Servlet API Servlet API主要有2个包,javax.servlet包含了servlet和web container使用的接口和类。javax.servlet.http包含了http相关的接口和类。 javax.servlet接口列表: Servlet ServletRequest ServletResponse RequestDispatcher ServletConfig ServletContext SingleThreadModel Filter FilterConfig FilterChain ServletRequestListener ServletRequestAttributeListener ServletContextListener ServletContextAttributeListener javax.servlet类列表: GenericServlet ServletInputStream ServletOutputStream ServletRequestWrapper ServletResponseWrapper ServletRequestEvent ServletContextEvent ServletRequestAttributeEvent ServletContextAttributeEvent ServletException UnavailableException javax.servlet.http接口列表: HttpServletRequest HttpServletResponse HttpSession HttpSessionListener HttpSessionAttributeListener HttpSessionBindingListener HttpSessionActivationListener HttpSessionContext (deprecated now) javax.servlet.http类列表: ...

关于SpringBoot开发的更多细节

在上篇文章《开发你的第一个SpringBoot应用》已经对SpringBoot基本开发流程有了大体了解,本文将继续对SpringBoot官网进行学习,发现关于SpringBoot开发的更多细节。