Переглянути джерело

2024年4月21日 18点31分

starlight_0208 5 місяців тому
батько
коміт
0358c328f5

+ 11 - 0
pom.xml

@@ -54,6 +54,17 @@
             <artifactId>c3p0</artifactId>
             <version>0.9.1.2</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-webmvc</artifactId>
+            <version>6.1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <version>3.1.0</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
     <dependencyManagement>
         <dependencies>

+ 46 - 0
src/main/java/org/starter/learning/config/ServletContainersInitConfig.java

@@ -0,0 +1,46 @@
+package org.starter.learning.config;
+
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.filter.CharacterEncodingFilter;
+import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
+import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
+
+
+public class ServletContainersInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
+
+    @Override
+    protected Class<?>[] getRootConfigClasses() {
+        return new Class[0];
+    }
+
+    @Override
+    protected Class<?>[] getServletConfigClasses() {
+        return new Class[0];
+    }
+
+    @Override
+    protected String[] getServletMappings() {
+        return new String[0];
+    }
+}
+
+//public class ServletContainersInitConfig extends AbstractDispatcherServletInitializer {
+//
+//    @Override
+//    protected WebApplicationContext createServletApplicationContext() {
+//        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
+//        ctx.register(SpringMvcConfig.class);
+//        return ctx;
+//    }
+//
+//    @Override
+//    protected String[] getServletMappings() {
+//        return new String[]{"/"};
+//    }
+//
+//    @Override
+//    protected WebApplicationContext createRootApplicationContext() {
+//        return null;
+//    }
+//}

+ 11 - 0
src/main/java/org/starter/learning/config/SpringMvcConfig.java

@@ -0,0 +1,11 @@
+package org.starter.learning.config;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+
+@Configuration
+@EnableWebMvc
+@ComponentScan("org.starter.learning.controller")
+public class SpringMvcConfig {
+}