zoukankan      html  css  js  c++  java
  • spring mvc Controller中使用@Value无法获取属性值

    在使用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 中把获取属性文件再定义一下
  • 相关阅读:
    POJ 2112 二分+最大流
    POJ 3281 最大流
    枚举------暴力与优化
    动态规划入门
    简单二叉树
    花式WA
    18年第十二届东北四省赛
    18年第十三届黑龙江省赛
    ACM中的java的使用;
    CF#483(div2 C)
  • 原文地址:https://www.cnblogs.com/shihaiming/p/5764263.html
Copyright © 2011-2022 走看看