ãµã¼ãã¬ããã§é¢åãªã®ã¯Tomcatã¨ã®ä»ãåãã§ãã
Spring Bootã§Spring Webã使ãã¨çµã¿è¾¼ã¿Tomcatãåãã®ã§ãTomcatã®ãã¨ãæ°ã«ããªãã¦ãããªãã¾ããã
ããã§ãµã¼ãã¬ããåããã¨åå¼·ãããããã§ã¯ãã¨æã£ãã®ã§è©¦ãã¦ã¿ã¾ãã
ã¾ããspring initializrã§Spring Webã追å ããããã¸ã§ã¯ããä½ãã¾ãã
https://start.spring.io/
ãã®ãªã³ã¯ãããè¨å®æ¸ã¿ã®spring initializrãéãã¾ããMavenã«ãã¦ããã®ã§ãGradleããã人ã¯é¸æããªããã¦ãã ããã
https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.1.1&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=demo&name=ServletDemo&description=Servlet%20Demo%20project%20for%20Spring%20Boot&packageName=com.example.servletdemo&dependencies=web
[GENERATE]ãã¿ã³ãæ¼ãã¦ãã¦ã³ãã¼ãããzipã解åãã¾ãããããªæãã«ãªã£ã¦ããã¯ãã
ã¢ããªã±ã¼ã·ã§ã³ã¯ã©ã¹ã« @ServletComponentScan
ãä»ãã¾ãã
package com.example.servletdemo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; @SpringBootApplication @ServletComponentScan public class ServletDemoApplication { public static void main(String[] args) { SpringApplication.run(ServletDemoApplication.class, args); } }
ããã¦ãµã¼ãã¬ããã¯ã©ã¹ãå®ç¾©ãã¾ãã
ãµã¼ãã¬ããã®ããã±ã¼ã¸ãjakartaã«ãªã£ã¦ãã®ã¯ææ
¨æ·±ãã
package com.example.servletdemo; import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @WebServlet(urlPatterns = "/hello") public class SampleServlet extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().println(""" <h1>Hello Servlet</h1> Hello! """); } }
ã¢ããªã±ã¼ã·ã§ã³ã¯ã©ã¹ãå®è¡ãããã¨ãSpring Bootãèµ·åãã¾ãã
http://localhost:8080/hello
ã«ã¢ã¯ã»ã¹ããã¨ã»ã»ã»
ã§ãã¾ããï¼
ããã§ããã®ã§ã¯ããªã¼ããªãã¼ããªã©ã使ããã¨æãã®ã§ãããªã楽ãã§ãããã
ãã ããJSPãåãããã¨ããã¨çµæ§ããã©ãã®ã§ããããªãæåããJakartaEEã使ãã»ããããããããããã¢ããªãµã¼ãã¼ã®ã¤ã³ã¹ãã¼ã«ãèµ·åããããã¤ãªã©ããããªãã¦ããããã«ãªã£ã¦ãã¾ãã
èµ·åãã¢ã¯ã»ã¹ãã¼ãã¯ã©ã³ã¿ã¤ã ãã¨ã«éãã®ã§ããã¦ã³ãã¼ãæã«ã¤ãã¦ããreadmeã確èªããå¿
è¦ãããã¾ãã
https://start.jakarta.ee/