• 关于在写拦截器时遇到的问题


    现在很多项目都是用springboot写的,那么在使用过程中肯定会出现很多不可预知的错误,

    在写拦截器和过滤器的过程中,

    @Configuration

    这个注解,可谓是坑人无数啊。。。

    从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,

    这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描,

    并用于构建bean定义,初始化Spring容器。

    @Configuration标注在类上,相当于把该类作为spring的xml配置文件中的<beans>,作用为:配置spring容器(应用上下文)


    package com.dxz.demo.configuration;

    import org.springframework.context.annotation.Configuration;

    @Configuration
    public class TestConfiguration {
    public TestConfiguration() {
    System.out.println("TestConfiguration容器启动初始化。。。");
    }
    }

    这段代码,就像spring的一个xml配置文件

    用于替换了

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd" default-lazy-init="false">


    </beans>

    同时,在拦截器的注册中心上要加上@Configuration这个注解,不然spring是不会扫描这个class类的

  • 相关阅读:
    cocos2d-x lua 学习笔记(1) -- 环境搭建
    Cocos2d-x 3.x 如何编译成安卓程序
    Cocos2d-x 3.4 初体验——安装教程
    cocos2d-x 之 CCProgressTimer
    android sdk离线安装
    在cocos2d-x-3.0 android 平台编译时提示CocosGUI.h: No such file or directory
    cocos2d_x iconv转码
    cocos2d-x发生undefined reference to `XX'异常 一劳永逸解决办法
    libjpeg.a exists or that its path is correct
    UE4插件
  • 原文地址:https://www.cnblogs.com/zhq-blogs/p/8391566.html
Copyright © 2020-2023  润新知