Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我试图通过spring将bean注入servlet过滤器时,返回Null值_Java_Spring_Filter - Fatal编程技术网

Java 当我试图通过spring将bean注入servlet过滤器时,返回Null值

Java 当我试图通过spring将bean注入servlet过滤器时,返回Null值,java,spring,filter,Java,Spring,Filter,My web.xml: <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name&

My web.xml:

<filter>
   <filter-name>springSecurityFilterChain</filter-name>
   <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
   <filter-name>springSecurityFilterChain</filter-name>
   <url-pattern>*.xhtml</url-pattern>
</filter-mapping>

<!--Listeners-->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<!--Params-->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:*-applicationContext.xml</param-value>
</context-param>

springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
*.xhtml
org.springframework.web.context.ContextLoaderListener
org.springframework.web.context.request.RequestContextListener
上下文配置位置
类路径*:*-applicationContext.xml
My applicationContext.xml:

<bean id="studentModel" class="ru.spb.herzen.jviewer.model.StudentModel" scope="session">
   <aop:scoped-proxy/>
</bean>
<bean id="sessionFilter" class="ru.spb.herzen.jviewer.filter.SessionFilter" init-method="init">
   <property name="userModel" ref="studentModel"/>
</bean>

<bean id="roleFilter" class="ru.spb.herzen.jviewer.filter.RoleFilter">
   <property name="userModel" ref="studentModel"/>
</bean>

<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
   <sec:filter-chain-map path-type="ant">
        <sec:filter-chain pattern="/**" filters="
            sessionFilter,
            roleFilter"/>
   </sec:filter-chain-map>
</bean>


当我尝试登录时,过滤器失败。在调试中,我看到userModel的值为null。我还尝试单独添加过滤器,但结果是一样的。我的错误在哪里?

我不知道这是否可能,但在黑暗中开枪。。。可能是因为您尚未登录,studentModel由于其“会话”而未创建scope@ns47731是的,但我在等待,该过滤器只有在我登录时才起作用。我如何才能做到这一点?@ns47731方法,在该方法中,我获取用户数据,在筛选之前调用,但在筛选中,用户数据为空。之前:LoginController-数据良好。之后:过滤器-数据为空。