2.1 springboot整合servlet

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16855077/article/details/84869949

1.整合Sevlet

1.1 通过注解扫描servlet组件的注册

1.1.1编写servlet

package com.cloudtech.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 测试spring boot注解方式整合HelloServlet
* @ClassName: HelloServlet  
* @Description:   
* @author wude  
* @date 2018年12月7日  
* 
 */
@WebServlet(name="helloServlet",urlPatterns="/do")
public class HelloServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("helloServlet.....");
		//super.doGet(req, resp);
	}
}

1.1.2编写启动类

package com.cloudtech;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

/**
 * springboot启动类
* @ClassName: App  
* @Description:   
* @author wude  
* @date 2018年12月6日  
*
 */
@SpringBootApplication
@ServletComponentScan  //在spring boot启动时,会扫描@webServlet,并将该类实例化
public class App {
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

 

猜你喜欢

转载自blog.csdn.net/qq_16855077/article/details/84869949
2.1