首页 > 编程语言 > 详细

spring mvc Controller中使用@Value无法获取属性值

时间:2016-10-20 15:29:53      阅读:232      评论:0      收藏:0      [点我收藏+]

在使用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 mvc Controller中使用@Value无法获取属性值

原文:http://www.cnblogs.com/itjcw/p/5980592.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!