|
|
|
@ -1,17 +1,17 @@
|
|
|
|
|
package com.yf.exam;
|
|
|
|
|
package com.yf.exam; // 定义包路径
|
|
|
|
|
|
|
|
|
|
import com.yf.exam.core.api.utils.JsonConverter;
|
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
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;
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.net.InetAddress; // 导入InetAddress类用于获取IP地址
|
|
|
|
|
import java.net.UnknownHostException; // 导入UnknownHostException异常类
|
|
|
|
|
import java.util.List; // 导入List集合类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 云帆在线考试系统
|
|
|
|
@ -19,23 +19,28 @@ import java.util.List;
|
|
|
|
|
* @email 18365918@qq.com
|
|
|
|
|
* @date 2020-03-04 19:41
|
|
|
|
|
*/
|
|
|
|
|
@Log4j2
|
|
|
|
|
@SpringBootApplication
|
|
|
|
|
public class ExamApplication implements WebMvcConfigurer {
|
|
|
|
|
@Log4j2 // 使用log4j2进行日志记录
|
|
|
|
|
@SpringBootApplication // 声明一个Spring Boot应用程序
|
|
|
|
|
public class ExamApplication implements WebMvcConfigurer { // 实现WebMvcConfigurer接口,定制MVC配置
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws UnknownHostException {
|
|
|
|
|
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" +
|
|
|
|
@ -45,9 +50,8 @@ public class ExamApplication implements WebMvcConfigurer {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
|
|
//保留原有converter,把新增fastConverter插入集合头,保证优先级
|
|
|
|
|
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { // 扩展Spring MVC的消息转换器
|
|
|
|
|
// 保留原有的消息转换器,将新的fastConverter插入到集合的头部,确保其优先级
|
|
|
|
|
converters.add(0, JsonConverter.fastConverter());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|