记录一次因代理Controller产生的404问题
spring 3.2.4
为了给每一个controller配置一个拦截器链
- import com.google.common.collect.Lists;
- import org.aopalliance.intercept.MethodInterceptor;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.aop.TargetSource;
- import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
- import org.springframework.beans.BeansException;
- import org.springframework.beans.factory.BeanFactory;
- import org.springframework.beans.factory.InitializingBean;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- import org.springframework.core.annotation.AnnotationUtils;
- import org.springframework.stereotype.Component;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import java.util.List;
- @Component
- public class AutoProxyCreator extends AbstractAutoProxyCreator implements InitializingBean {
- /**
- * 序列化版本号
- */
- private static final long serialVersionUID = 1L;
- /**
- * 持有Spring应用上下文
- */
- private volatile ApplicationContext context = null;
- /**
- * 日志打印
- */
- private static Logger logger = LoggerFactory.getLogger(AutoProxyCreator.class);
- /**
- * 拦截器链
- */
- private List<String> intercaptorChainList = null;
- /**
- * 实现自动代理
- */
- @Override
- protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource targetSource) {
- // 针对Controller和RequestMapping进行拦截
- if (AnnotationUtils.findAnnotation(beanClass, Controller.class) != null || AnnotationUtils.findAnnotation(beanClass, RequestMapping.class) != null) {
- if (intercaptorChainList == null) {
- throw new RuntimeException("初始化拦截器链失败,异常中断程序!");
- }
- List<MethodInterceptor> methodInterceptorList = Lists.newArrayList();
- for(String intercaptor : intercaptorChainList){
- if(AnnotationUtils.findAnnotation(beanClass, ExceptedAuthValidate.class) != null ){
- continue;
- }
- logger.info("开始为bean:\"{}\"配置拦截器链:\"{}\"", beanClass, intercaptor);
- BeanFactory beanFactory = getBeanFactory();
- MethodInterceptor methodInterceptor = (MethodInterceptor)beanFactory.getBean(intercaptor);
- methodInterceptorList.add(methodInterceptor);
- }
- return methodInterceptorList.toArray();
- }
- return DO_NOT_PROXY;
- }
- /**
- * 初始化拦截器链
- */
- @Override
- public void afterPropertiesSet() throws Exception {
- intercaptorChainList = Lists.newArrayList();
- intercaptorChainList.add("userLoginInterceptor");
- intercaptorChainList.add("paramValidateInterceptor");
- }
- }
然后跑起来发现所有的controller都访问不了了
AbstractHandlerMethodMapping里打断点可以看到
被代理了之后,getType出来是代理类,代理类没有注解
被认为不是一个handler
但是普通的AOP却没有问题,还需要了解AOP和这种代理有什么区别
记录一次因代理Controller产生的404问题的更多相关文章
- springboot搭建环境访问Controller层返回404
如果启动成功,但是却访问不了你自己写的controller,报404错误,那么原因就是您写的controller没有被spring 容器扫描到 解决方案: spring boot 默认扫描您的类是 在 ...
- 记录下使用iis7代理node.js写的网站程序
昨天晚上一个学弟的紧急求救,说了自己接的单子做了一个网站,使用了自己熟悉的技术——node.js+mongdb,但当看到部署环境惊呆了,是 windows+sqlserver.这些都不是关键,关键是服 ...
- idea创建springmvc项目创部署成功,但访问controller层报错404
这个问题网上有很多解决问题,检查配置文件是否正确?controller注解是否扫描?项目启动是否成功等等. 访问报错404,而且后台也没错误,归根结底还是访问路径错了. 1.如图,idea配置tomc ...
- 记录一次MVC 3.0错误 HTTP 404您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。
在部署到IIS7时,MVC3报了一个找不到资源的错误,文件肯定是有的,而且页面是肯定报错的,也就说内部运行错误了,而MVC把错误没有抛出来而已: 所以对症下药,发觉我的项目里面用了rexs进行多语言, ...
- springmvc 请求无法到达controller,出现404
今天在配置SpringMVC时,访问项目一直出现404,无法访问. 报错: The origin server did not find a current representation for th ...
- 记录一次 Nginx 配置 proxy_pass 后 返回404问题
一. Nginx 配置 proxy_pass 后 返回404问题 故障解决和定位 1.1. 问题 在一次生产涉及多次转发的配置中, 需求是下面的图: 在配置好了 proxy_pass 之后,请求 ww ...
- <mvc:default-servlet-handler/>导致controller失效,报404错误
最近在做ssm框架整合的一个小项目时,页面跳转一直有404错误,也没有报错提示.然后一步一步去找,终于发现是<mvc:default-servlet-handler/>的原因.如下图所示, ...
- spring请求到达controller但响应404
问题是这样的,前台发送请求的后台,后台的方法正常执行,将数据放在response.getWrite里,但在前台并没有展示数据.用浏览器的开发者工具看下请求,发现响应404. 最后网上查了查,sprin ...
- Java动态代理全面分析
代理模式 解说:给某一个对象提供一个代理,并由代理对象控制对原对象的引用: 代理模式需要以下几个角色: 1 主题:规定代理类和真实对象共同对外暴露的接口: 2 代理类:专门代理真实对象的类: 3 ...
随机推荐
- sort和uniq去重操作【转】
去除重复行 sort file |uniq 查找非重复行 sort file |uniq -u 查找重复行 sort file |uniq -d 统计 sort file | uniq - ...
- webpack打包生成多个vendor的配置方法
用webpack打包项目的时候,一般喜欢把一些公用的库打包的vendor.js里面,比如像react,react-router,redux等. 随着引入的库越来越多,vendor文件也变得越来越大,于 ...
- python3+selenium入门11-窗口切换
在打开新的浏览器窗口时,如果要定位新窗口的元素,需要先切换到这个新打开的窗口中,才能定位到该窗口下的元素. current_window_handle:获取当前句柄.可以把句柄理解成窗口的身份证 wi ...
- Css样式压缩、美化、净化工具 源代码
主要功能如下: /* 美化:格式化代码,使之容易阅读 */ /* 净化:将代码单行化,并去除注释 */ /* 压缩:将代码最小化,加快加载速度 */ /* 以下是演示代码 */ /*reset beg ...
- 安装snap及snap常安装软件
文章链接:https://blog.csdn.net/laomd/article/details/80710451 一.snap简介 什么是snap,snap是一种全新的软件包管理方式,它类似一个容器 ...
- nikto for windows(web扫描工具) 使用教程
本文出处: 欧普软件 ----------------------------------------------------------------------------------------- ...
- Confluence 6 管理站点模板
模板是一个预先定义的页面,这个预先定义的页面可以在创建新页面的时候预先载入.模板可以由用户创建也可以通过蓝图提供.请查看 Page Templates 和 Blueprints 页面中的内容. 管理员 ...
- ios消息机制
ios消息机制介绍 ios 调用每一个方法的时候其实是走的ios的消息机制 举例介绍一下 创建一个Pserson类 有一个eat 对象方法 那么下面的代码可以用消息机制实现 导入消息头文件 # ...
- 电子书转换为PDF格式
目录 一.mobi 转换 pdf 步骤 二.查看转换后的结果目录 三.将PDF还原文件名且移出至新目录 背景:当我们从网上下载一些电子小说或书籍的时候,一般文件的格式可能是.epub..mobi等.这 ...
- django----图书管理
待完成 from django.db import models # Create your models here. class Book(models.Model): nid = models.A ...