读书人

自定义标签怎么进行spring的@Autowired

发布时间: 2013-11-29 13:49:33 作者: rapoo

自定义标签如何进行spring的@Autowired
自定义了一个tag,里面需要引用到service层,利用@Autowired注解,永远得不到service对象,这是为什么呢

public class CataTag extends BodyTagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;

@Autowired
public HSListViewComponent sysCataViewComponent;

[解决办法]
spring 配置文件 applicationContext.xml 里加入
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>  
了没,Spring 通过一个 BeanPostProcessor 对 @Autowired 进行解析,所以要让 @Autowired 起作用必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。
[解决办法]
因为它没被Spring托管 所以写注解白写

读书人网 >Java Web开发

热点推荐