现在的位置: 首页 > 综合 > 正文

关于Struts在Spring中使用autowired 自动注入的问题

2017年12月26日 ⁄ 综合 ⁄ 共 540字 ⁄ 字号 评论关闭

如题 ,如果想要在struts里面使用spring 自动注入的话,有三个步骤

1.导入struts提供给spring 的插件包"struts-spring-pluging***.jar"

2.打开annotation自动注入功能,这里有两种方法:

         1.使用<context:annotation-config/>直接打开自动注入功能

         2.使用annotation 扫描功能,这个除了扫描和加入其包下面的所有bean 外,还自动开启annotation自动注入功能

	<context:component-scan base-package="com.sharp.ssh" use-default-filters="false">
		<context:include-filter type="regex" expression="com.sharp.ssh.service.impl.*"/>
		<context:include-filter type="regex" expression="com.sharp.ssh.dao.impl.*"/>
	</context:component-scan>


3.使用@autowired修饰要注入的类

本人在第二步犯了错,找了好久才找到原因, 引以为戒!

抱歉!评论已关闭.