This commit is contained in:
2026-10-23 08:35:42 +08:00
parent 29957d9b3b
commit ffb7abcbce
6 changed files with 32 additions and 2 deletions
@@ -3,6 +3,7 @@ package com.ycjy.Impl;
import com.ycjy.interfaces.MyAppInit;
import com.ycjy.servlet.FirstServlet;
import com.ycjy.servlet.SecondServlet;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRegistration;
@@ -9,7 +9,7 @@ import jakarta.servlet.annotation.HandlesTypes;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
//@HandlesTypes(MyAppInit.class) //告诉容器"把所有实现 MyAppInit 的类塞进 set"
@HandlesTypes(MyAppInit.class) //告诉容器"把所有实现 MyAppInit 的类塞进 set"
public class MyInit implements ServletContainerInitializer {
@Override
public void onStartup(Set<Class<?>> set, ServletContext ctx) throws ServletException {
@@ -1,16 +1,26 @@
package com.ycjy;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRegistration;
import org.jspecify.annotations.Nullable;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
//public class MyMvcAppInit implements WebApplicationInitializer {
// @Override
// public void onStartup(ServletContext servletContext) throws ServletException {
// // 基于注解配置的 Web 应用上下文简称容器
// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
// context.setServletContext(servletContext);
// context.register(MySystemConfig.class);
// context.refresh(); // 刷新, 然后容器才开始真正去扫描包
//
// ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
// DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
//
// ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
// dispatcher.addMapping("/");
// }
//}
@@ -1,8 +1,11 @@
package com.ycjy.controller;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;
import java.io.IOException;
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.linlangjz</groupId>
<artifactId>SpringStudy</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Spring-ch10-backend</artifactId>
</project>
+1
View File
@@ -17,6 +17,7 @@
<module>SpringFramework-Affairs</module>
<module>SpringFramework-MVC</module>
<module>Spring-ch09</module>
<module>Spring-ch10-backend</module>
</modules>
<properties>