首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

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

2012-10-23 
spring在filter里面如何获取注解方式定义的bean比如我有一个filter,继承OncePerRequestFilter或者直接实现

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> 

热点排行