问题描述
在过滤器Filter里面定义变量 用@Value给其赋值,为什么一直都是NULL
解决方案
必须是spring管理的bean才能注入
解决方案二:
可以参考https://github.com/zhangkaitao/es/blob/master/web/src/main/webapp/WEB-INF/web.xml<filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter>DelegatingFilterProxy自动到spring容器里找一个名字为shiroFilter的bean,完成任务https://github.com/zhangkaitao/es/blob/master/web/src/main/resources/spring-config-shiro.xml <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager"/> <!-- override these for application-specific URLs if you like:--> <property name="loginUrl" value="${shiro.login.url}"/> <property name="unauthorizedUrl" value="${shiro.unauthorizedUrl}"/> <!-- The 'filters' property is not necessary since any declared javax.servlet.Filter bean --> <!-- defined will be automatically acquired and available via its beanName in chain -->