springboot中使用servlet通过配置类
在servlet目录下创建个servlet类,示例代码如下:
package com.bjpowernode.springboot.servlet; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; public class HeServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("he springboot servlet");
resp.getWriter().flush();
resp.getWriter().close(); } @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req,resp);
}
}
编写配置类:
package com.bjpowernode.springboot.config; import com.bjpowernode.springboot.servlet.HeServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.servlet.ServletRegistration; @Configuration
public class ServletConfig { @Bean
public ServletRegistrationBean heServletRegisterBen() {
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
new HeServlet(), "/servlet/heservlet"
);
return servletRegistrationBean;
}
}
注意需要加的两个注解:@Configuration 还有@Bean
然后就可以启动springboot项目访问地址:http://localhost:8080/servlet/heservlet
进行测试了。
springboot中使用servlet通过配置类的更多相关文章
- springboot中使用filter用配置类方式
在03-springboot-web的Filter包下,创建HeFilter类 代码示例: package com.bjpowernode.springboot.filter; import java ...
- SpringBoot中使用UEditor基本配置(图文详解)
SpringBoot中使用UEditor基本配置(图文详解) 2018年03月12日 10:52:32 BigPotR 阅读数:4497 最近因工作需要,在自己研究百度的富文本编辑器UEditor ...
- springmvc以及springboot中的拦截器配置
拦截器两种实现 如果不同的controller中都需要拦截器,不能使用相同的拦截器,因为拦截器不能跨controller,这个时候只能为不同的controller配置不同的拦截器,每一个拦截器只能 ...
- SpringBoot中使用Servlet,Filter,Listener
项目最近在替换之前陈旧的框架,改用SpringBoot进行重构,初接触,暂时还没有用到Servlet,Filter,Listener的地方,但在之前回顾Servlet的生命周期时,https://ww ...
- Springboot中SpringMvc拦截器配置与应用(实战)
一.什么是拦截器,及其作用 拦截器(Interceptor): 用于在某个方法被访问之前进行拦截,然后在方法执行之前或之后加入某些操作,其实就是AOP的一种实现策略.它通过动态拦截Action调用的对 ...
- SpringBoot中SpringMVC的自动配置以及扩展
一.问题引入 我们在SSM中使用SpringMVC的时候,需要由我们自己写SpringMVC的配置文件,需要用到什么就要自己配什么,配置起来也特别的麻烦.我们使用SpringBoot的时候没有进行配置 ...
- SpringBoot中application.yml基本配置详情
把原有的application.properties删掉.然后 maven -X clean install,或者通过Maven Project双击clean和install(1)端口服务配置 #端口 ...
- SpringBoot中加载XML配置
开篇 在SpringBoot中我们通常都是基于注解来开发的,实话说其实这个功能比较鸡肋,但是,SpringBoot中还是能做到的.所以用不用是一回事,会不会又是另外一回事. 涛锅锅在个人能力能掌握的范 ...
- SpringBoot中自定义properties文件配置参数并带有输入提示
1. 创建配置类 在项目中创建一个参数映射类如下 @ConfigurationProperties(prefix = "user.info") public class MyPro ...
随机推荐
- 六十四:CSRF攻击与防御之系统准备之病毒网站转账实现
准备一个页面或图片,用于用户访问 一:表单方式 视图 from flask import Flask, render_template app = Flask(__name__) @app.route ...
- Linux 源码安装nginx
编译参数详解:https://www.cnblogs.com/houyongchong/p/compileArgs.html 配置参数详解:https://www.cnblogs.com/houyon ...
- CKeditor从Word粘贴格式问题
在config.js中添加配置 config.pasteFromWordRemoveFontStyles = false; config.pasteFromWordRemoveStyles = ...
- Tomcat远程调试参数
Linux: 关闭防火墙 vim catalina.sh export CATALINA_OPTS="-server -Xdebug -Xnoagent -Djava.compiler=NO ...
- ELK 日志平台构建
elastic中文社区 https://elasticsearch.cn/ 完整参考 ELK实时日志分析平台环境部署--完整记录 https://www.cnblogs.com/kevingrace/ ...
- React Native 安装
第一 :在天朝如果你可以违规上网的话便可以按 react native 中文网的文档进行安装与调试.地址为:https://reactnative.cn/docs/getting-started.ht ...
- .net core cookie滑动过期设置
HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new Authe ...
- Linux C\C++基础 字符数组、字符串和字符串常量
1.字符数组和字符串 C语言没有字符串类型,用字符数组模拟 字符串一定是字符数组,字符数组不一定是字符串 如果字符数组以字符'\0'('\0'等同与数字0)结尾,那么这个字符数组就是字符串 char ...
- numpy的divide函数
和直接用/一样,都是矩阵的对应元素相除. 如果用*,那么是矩阵的对应元素相乘. 如果要实现矩阵乘法,用numpy的dot函数.
- C#实现多线程的方式:使用Parallel类
简介 在C#中实现多线程的另一个方式是使用Parallel类. 在.NET4中 ,另一个新增的抽象线程是Parallel类 .这个类定义了并行的for和foreach的 静态方法.在为 for和 f ...