|
|
|
@ -1,21 +1,54 @@
|
|
|
|
|
package com;
|
|
|
|
|
|
|
|
|
|
// 导入 MyBatis-Spring 框架提供的注解,用于扫描指定包下的 Mapper 接口
|
|
|
|
|
// 扫描后 Spring 会自动为这些接口创建代理对象,从而实现数据库操作
|
|
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
|
// 导入 Spring Boot 应用启动相关的类,该类可用于启动 Spring Boot 应用
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
// 导入 Spring Boot 自动配置注解,启用 Spring Boot 的自动配置功能
|
|
|
|
|
// 它会根据项目依赖自动配置 Spring 应用的各种组件
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
// 导入 Spring Boot 应用构建器类,用于构建 Spring Boot 应用实例
|
|
|
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
|
|
// 导入 Spring Boot 支持 Servlet 容器部署的初始化器类
|
|
|
|
|
// 继承该类可使 Spring Boot 应用以 WAR 包形式部署到外部 Servlet 容器
|
|
|
|
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Spring Boot 应用的主类,作为整个应用的启动入口。
|
|
|
|
|
* 它整合了 Spring Boot 的自动配置功能和 MyBatis 的 Mapper 扫描功能,
|
|
|
|
|
* 并且支持将应用打包成 WAR 包部署到外部 Servlet 容器中。
|
|
|
|
|
*/
|
|
|
|
|
@SpringBootApplication
|
|
|
|
|
// 此注解用于指定 MyBatis 要扫描的 Mapper 接口所在的包路径
|
|
|
|
|
// 这里指定扫描 "com.dao" 包,Spring 会为该包下的 Mapper 接口生成代理实现
|
|
|
|
|
@MapperScan(basePackages = {"com.dao"})
|
|
|
|
|
public class SpringbootSchemaApplication extends SpringBootServletInitializer{
|
|
|
|
|
public class SpringbootSchemaApplication extends SpringBootServletInitializer {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 应用的主方法,是 Java 程序的入口点。
|
|
|
|
|
* 当启动 Spring Boot 应用时,会调用此方法,
|
|
|
|
|
* 通过 SpringApplication.run 方法启动 Spring Boot 应用上下文。
|
|
|
|
|
*
|
|
|
|
|
* @param args 命令行参数,可用于传递启动应用时的配置信息
|
|
|
|
|
*/
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
// 调用 SpringApplication 的 run 方法来启动 Spring Boot 应用
|
|
|
|
|
// 传入当前类的 Class 对象和命令行参数
|
|
|
|
|
SpringApplication.run(SpringbootSchemaApplication.class, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重写 SpringBootServletInitializer 类的 configure 方法,
|
|
|
|
|
* 该方法用于配置 Spring Boot 应用在外部 Servlet 容器中运行时的启动行为。
|
|
|
|
|
* 当将应用打包成 WAR 包部署到外部 Servlet 容器(如 Tomcat)时会调用此方法。
|
|
|
|
|
*
|
|
|
|
|
* @param applicationBuilder SpringApplicationBuilder 对象,用于构建 Spring Boot 应用
|
|
|
|
|
* @return 配置好的 SpringApplicationBuilder 对象,指定应用的主类为当前类
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
|
|
|
|
|
return applicationBuilder.sources(SpringbootSchemaApplication.class);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
|
|
|
|
|
// 设置 Spring Boot 应用的主类为当前类,确保在外部 Servlet 容器中正确启动
|
|
|
|
|
return applicationBuilder.sources(SpringbootSchemaApplication.class);
|
|
|
|
|
}
|
|
|
|
|
}
|