码迷,mamicode.com
首页 > 移动开发 > 详细

spring controller中@Value取不到applicationContext.xml中加载配置文件的问题

时间:2015-06-23 17:24:03      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

原因还未查证: http://sunjun041640.blog.163.com/blog/static/256268322014127113844746/

 

在使用spring mvc时,实际上是两个spring容器:

1,dispatcher-servlet.xml 是一个,我们的controller就在这里,所以这个里面也需要注入属性文件
org.springframework.web.servlet.DispatcherServlet
这里最终是使用WebApplicationContext parent =WebApplicationContextUtils.getWebApplicationContext(getServletContext()); 创建spring容器,代码在FrameworkServlet中
 
2,applicationContext.xml 是另外一个,也需要注入属性文件
org.springframework.web.context.ContextLoaderListener
 
在我们的service中可以拿到@Value注入的值,那是因为我们通常都会把获取属性文件定义在applicationContext.xml中,这样在 Controller中是取不到的,必须在dispatcher-servlet.xml 中把获取属性文件再定义一下

spring controller中@Value取不到applicationContext.xml中加载配置文件的问题

标签:

原文地址:http://www.cnblogs.com/kevin-yuan/p/4595742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!