【问题标题】:Error creating bean with name '_filterChainProxy': Initialization of bean failed; nested exception is java.lang.NullPointerException创建名为“_filterChainProxy”的 bean 时出错:bean 初始化失败;嵌套异常是 java.lang.NullPointerException
【发布时间】:2011-04-13 13:02:04
【问题描述】:

applicationContext.xml:

<bean id="defaultEntryPoint" class="com.spsetia.companyapp.company.services.CustomAuthenticationEntryPoint">
    <property name="securityConfiguration" ref="securityConfiguration" />
    <!-- Default filter chain proxy -->
    <property name="proxy" ref="_filterChainProxy" />
</bean>

web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml
    </param-value>
  </context-param>
 <filter>
    <filter-name>redirect</filter-name>
    <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
  </filter>
 <filter-mapping>
    <filter-name>redirect</filter-name>
    <url-pattern>/</url-pattern>
  </filter-mapping>
 <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>
 <filter>
  <filter-name>_filterChainProxy</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
  <filter-name>_filterChainProxy</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
    <listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
</listener>
  <servlet>
    <servlet-name>app</servlet-name>
    <servlet-class>
      org.apache.tapestry.ApplicationServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

但我收到此错误:

org.springframework.beans.factory.BeanCreationException: 创建具有名称的 bean 时出错 “_filterChainList”:无法解析 参考豆 '_exceptionTranslationFilter' 同时 使用设置 bean 属性“过滤器” 键[2];嵌套异常是 org.springframework.beans.factory.BeanCreationException: 创建具有名称的 bean 时出错 '_exceptionTranslationFilter': bean初始化失败;嵌套的 例外是 org.springframework.beans.factory.BeanCreationException: 创建具有名称的 bean 时出错 'defaultEntryPoint' 定义在 ServletContext 资源 [/WEB-INF/applicationContext.xml]: 无法解析对 bean 的引用 设置bean时的'_filterChainProxy' 属性“代理”;嵌套异常是 org.springframework.beans.factory.BeanCreationException: 创建具有名称的 bean 时出错 '_filterChainProxy':初始化 豆失败;嵌套异常是 java.lang.NullPointerException

我做错了什么?

【问题讨论】:

  • @Bozho,我查看了堆栈跟踪,但我没有看到任何重要信息。我可以知道我是否需要在 applicationContext.xml 中定义 id=_filterChainProxy 的 bean?因为我只在 web.xml 中定义了它。

标签: java spring spring-security


【解决方案1】:
FilterChainList filterList = (FilterChainList) 
    beanFactory.getBean(BeanIds.FILTER_LIST);

List filters = new ArrayList(filterList.getFilters());

这些行是问题所在。这意味着名为_filterChainList(上述常量的值)的bean 必须有一组为其定义的过滤器。

【讨论】:

    【解决方案2】:

    看来您必须使用 SpringSecurity 2.0.x 或 2.5.x。 3.0.x 代码库中似乎不存在 FilterChainProxyPostProcessor 类。

    经过一番挖掘,我找到了您的异常似乎起源的代码:

    public Object postProcessBeforeInitialization(Object bean, String beanName) 
    throws BeansException {
        if(!BeanIds.FILTER_CHAIN_PROXY.equals(beanName)) {
            return bean;
        }
    
        FilterChainProxy filterChainProxy = (FilterChainProxy) bean;
        FilterChainList filterList = 
            (FilterChainList) beanFactory.getBean(BeanIds.FILTER_LIST);
    
        List filters = new ArrayList(filterList.getFilters());
        Collections.sort(filters, new OrderComparator());
    

    我的诊断是 NPE 在创建 ArrayList 的行上被抛出,这是由于 filterList.getFilters() 返回 null。回过头来看,原因似乎是“_filterChainList”bean 没有被正确初始化。

    我不知道应该如何或在哪里初始化它......

    【讨论】:

      猜你喜欢
      • 2014-12-09
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多