「Spring Boot」Servlet、Filter、Listenerの登録のサンプル
書式
@Bean
public ServletRegistrationBean 関数名
使用例
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author Java */ public class RegisterServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse rep) throws IOException { String name = getServletConfig().getInitParameter("name"); String sex = getServletConfig().getInitParameter("password"); rep.getOutputStream().println("name is " + name); rep.getOutputStream().println("password is " + password); } } @Bean public ServletRegistrationBean registerServlet() { ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean( new RegisterServlet(), "/registerServlet"); servletRegistrationBean.addInitParameter("name", "user007"); servletRegistrationBean.addInitParameter("password", "123456"); return servletRegistrationBean; }