当前位置: 代码迷 >> J2SE >> spring在filter里面怎么获取注解方式定义的bean
  详细解决方案

spring在filter里面怎么获取注解方式定义的bean

热度:7586   发布时间:2013-02-25 00:00:00.0
spring在filter里面如何获取注解方式定义的bean
比如我有一个filter,继承OncePerRequestFilter或者直接实现http filter
然后我通过下面的方式可以获取到定义在applicationContext.xml中的bean
WebApplicationContext web = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
SystemFacade systemFacade = (SystemFacade)web.getBean("systemFacade");

但是实际的情况是SystemFacade是一个注解方式配置的,而不是xml方式配置的。有什么方法可以获取到注解方式定义的bean吗?



------解决方案--------------------------------------------------------
注解方式定义的,依然要配XML文件让Spring去搜索。你可以在applicationContext.xml文件中做修改,参考代码如下:
HTML code
<?xml version="1.0"?><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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">  <context:component-scan base-package="beans" />    </beans>
  相关解决方案