读书人

关于当候选 Bean 数额不为 1 时的应对

发布时间: 2012-09-12 09:21:30 作者: rapoo

关于当候选 Bean 数目不为 1 时的应对方法
正确配置:
spring配置
A.配置命名空间
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

B.加入自动注入
<context:annotation-config/>
<context:component-scan base-package="net.shopxx"/>

C.spring组件
@Component("jcaptchaFilter")
public class JcaptchaFilter implements Filter {

D.引入需要注入的类
public class AdminAction extends ActionSupport {

@Autowired
@Qualifier("jcaptchaFilter")
private JcaptchaFilter jcaptchaFilter;

读书人网 >软件架构设计

热点推荐