diff --git a/src/main/java/org/joinfaces/example/JarExampleApplication.java b/src/main/java/org/joinfaces/example/JarExampleApplication.java index 9417025..707a919 100644 --- a/src/main/java/org/joinfaces/example/JarExampleApplication.java +++ b/src/main/java/org/joinfaces/example/JarExampleApplication.java @@ -2,11 +2,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; /** * @author Lars Grefer */ @SpringBootApplication +@ServletComponentScan public class JarExampleApplication { public static void main(String[] args) { diff --git a/src/main/java/org/joinfaces/example/WelcomePageServlet.java b/src/main/java/org/joinfaces/example/WelcomePageServlet.java new file mode 100644 index 0000000..b978e30 --- /dev/null +++ b/src/main/java/org/joinfaces/example/WelcomePageServlet.java @@ -0,0 +1,23 @@ +package org.joinfaces.example; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +/** + * @author Lars Grefer + */ +@WebServlet(urlPatterns = "/") +public class WelcomePageServlet extends GenericServlet { + + @Override + public void service(ServletRequest req, ServletResponse res) throws IOException { + if (res instanceof HttpServletResponse httpServletResponse) { + httpServletResponse.sendRedirect("/index.xhtml"); + } + } +} diff --git a/src/test/java/org/joinfaces/example/JarExampleApplicationTest.java b/src/test/java/org/joinfaces/example/JarExampleApplicationTest.java index 3ed7fd8..880eafa 100644 --- a/src/test/java/org/joinfaces/example/JarExampleApplicationTest.java +++ b/src/test/java/org/joinfaces/example/JarExampleApplicationTest.java @@ -24,6 +24,17 @@ public class JarExampleApplicationTest { public void testHelloFromSpring() { ResponseEntity entity = restTemplate.getForEntity("/index.xhtml", String.class); + checkResponse(entity); + } + + @Test + public void testWelcomePageRedirect() { + ResponseEntity entity = restTemplate.getForEntity("/", String.class); + + checkResponse(entity); + } + + private static void checkResponse(ResponseEntity entity) { assertThat(entity.getStatusCode().is2xxSuccessful()).isTrue(); assertThat(entity.getBody()).contains("Hello from Spring:");