diff --git a/demo-spring-webmvc-nonboot/README.md b/demo-spring-webmvc-nonboot/README.md new file mode 100644 index 0000000..b598067 --- /dev/null +++ b/demo-spring-webmvc-nonboot/README.md @@ -0,0 +1,37 @@ +# springdoc-openapi demo with non Spring Boot Spring Web MVC + +## Building application + +### Pre-requisites + +- JDK 17+ +- Maven 3+ + +### Build + +From the project root: + +```sh +mvn -pl demo-spring-webmvc-nonboot -am clean package +``` + +This will produce: + +```text +demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot.war +``` + + +## Run + +Deploy the generated WAR to a Servlet container (e.g. Tomcat). + +Assuming the context path is /demo-spring-webmvc-nonboot: + +- OpenAPI docs: /demo-spring-webmvc-nonboot/v3/api-docs +- Swagger UI: /demo-spring-webmvc-nonboot/swagger-ui/index.html +- Sample API: GET /demo-spring-webmvc-nonboot/api/hello + + +This is a Maven module. +Build it together with the other demos using your preferred Maven setup or IDE. diff --git a/demo-spring-webmvc-nonboot/pom.xml b/demo-spring-webmvc-nonboot/pom.xml new file mode 100644 index 0000000..7031dc7 --- /dev/null +++ b/demo-spring-webmvc-nonboot/pom.xml @@ -0,0 +1,96 @@ + + + + 4.0.0 + + + org.springdoc + springdoc-openapi-demos + 3.1.7-SNAPSHOT + ../pom.xml + + + demo-spring-webmvc-nonboot + Demo Spring Web MVC (non Spring Boot) with OpenAPI 3 + war + + + + org.springframework + spring-webmvc + + + + jakarta.servlet + jakarta.servlet-api + provided + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + org.springframework.boot + spring-boot-autoconfigure + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.springframework + spring-test + test + + + + org.junit.jupiter + junit-jupiter + test + + + + + demo-spring-webmvc-nonboot + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + org.eclipse.jetty + jetty-maven-plugin + 11.0.26 + + + /demo-spring-webmvc-nonboot + + + + + + maven-war-plugin + 3.4.0 + + false + + + + + + + diff --git a/demo-spring-webmvc-nonboot/src/main/java/org/springdoc/demo/nonboot/config/OpenApiConfiguration.java b/demo-spring-webmvc-nonboot/src/main/java/org/springdoc/demo/nonboot/config/OpenApiConfiguration.java new file mode 100644 index 0000000..cda980a --- /dev/null +++ b/demo-spring-webmvc-nonboot/src/main/java/org/springdoc/demo/nonboot/config/OpenApiConfiguration.java @@ -0,0 +1,45 @@ +package org.springdoc.demo.nonboot.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import org.springdoc.core.configuration.SpringDocConfiguration; +import org.springdoc.core.properties.SpringDocConfigProperties; +import org.springdoc.webmvc.core.configuration.SpringDocWebMvcConfiguration; +import org.springdoc.webmvc.ui.SwaggerConfig; +import org.springdoc.core.properties.SwaggerUiConfigProperties; +import org.springdoc.core.properties.SwaggerUiOAuthProperties; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = { + "org.springdoc.demo.nonboot.web" +}) +@Import({ + SpringDocConfiguration.class, + SpringDocWebMvcConfiguration.class, + SwaggerConfig.class, + SwaggerUiConfigProperties.class, + SwaggerUiOAuthProperties.class, + JacksonAutoConfiguration.class +}) +public class OpenApiConfiguration { + + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .info(new Info() + .title("Non Spring Boot Spring MVC demo API") + .version("v1")); + } + + @Bean + public SpringDocConfigProperties springDocConfigProperties() { + return new SpringDocConfigProperties(); + } +} diff --git a/demo-spring-webmvc-nonboot/src/main/java/org/springdoc/demo/nonboot/web/HelloController.java b/demo-spring-webmvc-nonboot/src/main/java/org/springdoc/demo/nonboot/web/HelloController.java new file mode 100644 index 0000000..9480165 --- /dev/null +++ b/demo-spring-webmvc-nonboot/src/main/java/org/springdoc/demo/nonboot/web/HelloController.java @@ -0,0 +1,20 @@ +package org.springdoc.demo.nonboot.web; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Tag(name = "Hello API", description = "Simple demo endpoint for non-boot Spring MVC") +public class HelloController { + + @GetMapping("/api/hello") + @Operation(summary = "Say hello", description = "Returns a simple greeting") + public Greeting hello() { + return new Greeting("Hello from non Spring Boot Spring MVC application!"); + } + + public record Greeting(String message) { + } +} diff --git a/demo-spring-webmvc-nonboot/src/main/webapp/WEB-INF/web.xml b/demo-spring-webmvc-nonboot/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9cf69cb --- /dev/null +++ b/demo-spring-webmvc-nonboot/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + springdoc non-boot spring-webmvc demo + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + + + contextClass + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.springdoc.demo.nonboot.config.OpenApiConfiguration + + + 1 + + + + dispatcher + / + + + diff --git a/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/MANIFEST.MF b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b32988c --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Created-By: Maven WAR Plugin 3.4.0 +Build-Jdk-Spec: 21 +Implementation-Title: Demo Spring Web MVC (non Spring Boot) with OpenAPI + 3 +Implementation-Version: 3.1.7-SNAPSHOT + diff --git a/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/maven/org.springdoc/demo-spring-webmvc-nonboot/pom.properties b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/maven/org.springdoc/demo-spring-webmvc-nonboot/pom.properties new file mode 100644 index 0000000..62682d6 --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/maven/org.springdoc/demo-spring-webmvc-nonboot/pom.properties @@ -0,0 +1,3 @@ +artifactId=demo-spring-webmvc-nonboot +groupId=org.springdoc +version=3.1.7-SNAPSHOT diff --git a/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/maven/org.springdoc/demo-spring-webmvc-nonboot/pom.xml b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/maven/org.springdoc/demo-spring-webmvc-nonboot/pom.xml new file mode 100644 index 0000000..7031dc7 --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/META-INF/maven/org.springdoc/demo-spring-webmvc-nonboot/pom.xml @@ -0,0 +1,96 @@ + + + + 4.0.0 + + + org.springdoc + springdoc-openapi-demos + 3.1.7-SNAPSHOT + ../pom.xml + + + demo-spring-webmvc-nonboot + Demo Spring Web MVC (non Spring Boot) with OpenAPI 3 + war + + + + org.springframework + spring-webmvc + + + + jakarta.servlet + jakarta.servlet-api + provided + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + org.springframework.boot + spring-boot-autoconfigure + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.springframework + spring-test + test + + + + org.junit.jupiter + junit-jupiter + test + + + + + demo-spring-webmvc-nonboot + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + org.eclipse.jetty + jetty-maven-plugin + 11.0.26 + + + /demo-spring-webmvc-nonboot + + + + + + maven-war-plugin + 3.4.0 + + false + + + + + + + diff --git a/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/WEB-INF/web.xml b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/WEB-INF/web.xml new file mode 100644 index 0000000..9cf69cb --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/demo-spring-webmvc-nonboot/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + springdoc non-boot spring-webmvc demo + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + + + contextClass + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.springdoc.demo.nonboot.config.OpenApiConfiguration + + + 1 + + + + dispatcher + / + + + diff --git a/demo-spring-webmvc-nonboot/target/maven-archiver/pom.properties b/demo-spring-webmvc-nonboot/target/maven-archiver/pom.properties new file mode 100644 index 0000000..62682d6 --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=demo-spring-webmvc-nonboot +groupId=org.springdoc +version=3.1.7-SNAPSHOT diff --git a/demo-spring-webmvc-nonboot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/demo-spring-webmvc-nonboot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..2764dfd --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +org\springdoc\demo\nonboot\config\OpenApiConfiguration.class +org\springdoc\demo\nonboot\web\HelloController.class +org\springdoc\demo\nonboot\web\HelloController$Greeting.class diff --git a/demo-spring-webmvc-nonboot/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/demo-spring-webmvc-nonboot/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..975532e --- /dev/null +++ b/demo-spring-webmvc-nonboot/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +D:\backup01\Documents\GitHub\springdoc-openapi-demos\demo-spring-webmvc-nonboot\src\main\java\org\springdoc\demo\nonboot\config\OpenApiConfiguration.java +D:\backup01\Documents\GitHub\springdoc-openapi-demos\demo-spring-webmvc-nonboot\src\main\java\org\springdoc\demo\nonboot\web\HelloController.java diff --git a/pom.xml b/pom.xml index a0d5317..15b6752 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,7 @@ demo-spring-cloud-function demo-spring-boot-webflux-scalar demo-spring-boot-webmvc-scalar + demo-spring-webmvc-nonboot