You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
test/src-源文件/main/java/com/yf/exam/ExamApplication.java

58 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.yf.exam; // 定义包路径
import com.yf.exam.core.api.utils.JsonConverter; // 导入JsonConverter工具类
import lombok.extern.log4j.Log4j2; // 导入log4j2日志工具
import org.springframework.boot.SpringApplication; // 导入Spring Boot的SpringApplication类
import org.springframework.boot.autoconfigure.SpringBootApplication; // 导入SpringBoot应用的启动注解
import org.springframework.context.ConfigurableApplicationContext; // 导入Spring上下文配置类
import org.springframework.core.env.Environment; // 导入Spring环境配置类
import org.springframework.http.converter.HttpMessageConverter; // 导入HTTP消息转换器接口
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; // 导入Web MVC配置接口
import java.net.InetAddress; // 导入InetAddress类用于获取IP地址
import java.net.UnknownHostException; // 导入UnknownHostException异常类
import java.util.List; // 导入List集合类
/**
* 云帆在线考试系统
* @author bool
* @email 18365918@qq.com
* @date 2020-03-04 19:41
*/
@Log4j2 // 使用log4j2进行日志记录
@SpringBootApplication // 声明一个Spring Boot应用程序
public class ExamApplication implements WebMvcConfigurer { // 实现WebMvcConfigurer接口定制MVC配置
public static void main(String[] args) throws UnknownHostException { // 主方法,应用程序入口
// 启动Spring Boot应用获取应用上下文
ConfigurableApplicationContext application = SpringApplication.run(ExamApplication.class, args);
// 获取环境配置信息
Environment env = application.getEnvironment();
// 获取本机IP地址
String ip = InetAddress.getLocalHost().getHostAddress();
// 获取端口号
String port = env.getProperty("server.port");
// 获取上下文路径
String path = env.getProperty("server.servlet.context-path");
// 如果没有配置路径,则默认为空字符串
if(path == null){
path = "";
}
// 输出启动信息到日志
log.info("\n----------------------------------------------------------\n\t" +
"云帆考试系统启动成功,访问路径如下:\n\t" +
"本地路径: \t\thttp://localhost:" + port + path + "/\n\t" +
"网络地址: \thttp://" + ip + ":" + port + path + "/\n\t" +
"API文档: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
"----------------------------------------------------------");
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { // 扩展Spring MVC的消息转换器
// 保留原有的消息转换器将新的fastConverter插入到集合的头部确保其优先级
converters.add(0, JsonConverter.fastConverter());
}
}