最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

原生注解方式注入web原生組件

2022-07-31 13:12 作者:限量版范兒  | 我要投稿
  • 使用原生注解注入servlet組件:@WebServlet處理請(qǐng)求路由,+主配置類(lèi)中標(biāo)注@ServletComponentScan掃描原生注解所在的路徑

  • @WebServlet(urlPatterns = "/my")

  • public class MyServlet extends HttpServlet {

  • @Override

  • protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

  • resp.getWriter().write("66666");

  • }

  • }


  • @MapperScan("com.atguigu.admin.mapper")

  • @ServletComponentScan(basePackages = "com.atguigu.admin")

  • @SpringBootApplication(exclude = RedisAutoConfiguration.class)

  • public class Boot05WebAdminApplication {

  • public static void main(String[] args) {

  • SpringApplication.run(Boot05WebAdminApplication.class, args);

  • }

  • }

  • ``


  • - 使用原生注解注入filter組件:@WebFilter + @ServletComponentScan


@Slf4j
@WebFilter(urlPatterns={"/css/","/images/"}) // 表示攔截該路徑下的靜態(tài)資源
public class MyFilter implements Filter {

  • @Override

  • public void init(FilterConfig filterConfig) throws ServletException {

  • log.info("MyFilter初始化完成");

  • }


  • @Override

  • public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

  • log.info("MyFilter工作"); ? // 攔截后進(jìn)行邏輯處理

  • chain.doFilter(request,response); ? // 最后放行,放行后可訪問(wèn)

  • }


  • @Override

  • public void destroy() {

  • log.info("MyFilter銷(xiāo)毀");

  • }


}


  • - 使用原生組件注入listener組件:@WebListener + @ServletComponentScan


@Slf4j
@WebListener
public class MyServletContextListener implements ServletContextListener {

  • @Override

  • public void contextInitialized(ServletContextEvent sce) {

  • log.info("MySwervletContextListener監(jiān)聽(tīng)到項(xiàng)目初始化完成");

  • }


  • @Override

  • public void contextDestroyed(ServletContextEvent sce) {

  • log.info("MySwervletContextListener監(jiān)聽(tīng)到項(xiàng)目銷(xiāo)毀");

  • }


}

來(lái)源鏈接:https://www.dianjilingqu.com/459502.html

原生注解方式注入web原生組件的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
越西县| 乌鲁木齐市| 霍城县| 卢龙县| 张北县| 承德市| 天台县| 浦江县| 大邑县| 清水县| 龙口市| 沁水县| 昌都县| 霍城县| 开远市| 白山市| 淮阳县| 苏尼特右旗| 武义县| 永宁县| 嘉义县| 吉林市| 炉霍县| 精河县| 宁化县| 盈江县| 保定市| 新河县| 波密县| 平谷区| 前郭尔| 武陟县| 定州市| 太湖县| 象州县| 凤凰县| 龙山县| 乌拉特前旗| 丹阳市| 阳西县| 米易县|