@Autowired的疑问

synized 2013-02-27 01:42:48

@Controller
@RequestMapping("/project")
public class EconomicBenefitsController
{
@Autowired //1
TargetInfoService targetInfoService;
@Autowired
public EconomicBenefitsController(TargetInfoService targetInfoService)
{
this.targetInfoService = targetInfoService;
}


<bean id="targetInfoService"class="cn.gov.tstc.project.close.service.TargetInfoService">
<property name="targetInfoMapper" ref="targetInfoMapper" />
</bean>

类用的@Controller来标识的bean只设置了targetInfoService, @Autowired 用来自动装配符合的bean,我debug的时候发现1处并没有自动装配,1处targetInfoService值为null,代码没什么问题,我想知道为什么1处用了@Autowired,targetInfoService的值为什么为null
...全文
111 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
-AJ- 2013-02-27
  • 打赏
  • 举报
回复
你加 @Service 了么?
浪里花 2013-02-27
  • 打赏
  • 举报
回复
启动spring容器没有,用服务器debug的还是用测试类debug的?以前我也遇到这个问题的了.
synized 2013-02-27
  • 打赏
  • 举报
回复
引用 1 楼 whos2002110 的回复:
注解驱动配置了么,<context:component-scan base-package="com.xxx.xxx" />
这个应该没关系

<context:component-scan base-package="cn.gov.tstc.project.close" />
我是debug这个操作进入这个类的 不自动验证注解也行 到@Autowired的时候应该会自动匹配
whos2002110 2013-02-27
  • 打赏
  • 举报
回复
注解驱动配置了么,<context:component-scan base-package="com.xxx.xxx" />

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧