问题描述

项目中的资源文件中写了个properties文件,内容这样的

CUST_FROM=002
CUST_INDUSTORY=001
CUST_LEVEL=006

在springmvc配置文件中加载设这样的

<context:property-placeholder location="classpath:resources.properties"/>
<context:component-scan base-package="com.crm.controller"/>

在spring中配置了注解扫描是这样

<context:component-scan base-package="com.crm"/>

最后在代码中调用

ackage com.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import com.crm.domain.BaseDict;
import com.crm.service.BaseDictService; @Controller
public class BaseDictController { @Autowired
private BaseDictService baseDictService; **@Value("${CUST_INDUSTORY}")**
private String CUST_INDUSTORY; **@Value("${CUST_LEVEL}")**
private String CUST_LEVEL; **@Value("${CUST_FROM}")**
private String CUST_FROM; @RequestMapping("basedict_list")
public String basedictList(Model model){
List<BaseDict> listFrom = baseDictService.queryBasedict(CUST_FROM);
List<BaseDict> listIndustory = baseDictService.queryBasedict(CUST_INDUSTORY);
List<BaseDict> listLevel = baseDictService.queryBasedict(CUST_LEVEL);
model.addAttribute("fromType", listFrom);
model.addAttribute("industryType", listIndustory);
model.addAttribute("levelType", listLevel); return "list";
} }

问题分析和解决方案

出现这个错误其实说一个spring父子容器的问题 
我在spring中配置的注解扫描,会将带注解的所有的对象进行依赖注入,并完成实例化,我在spring容器中并没有加载我自定义的properties文件,所以spring在依赖注入时在容器中找不到这些属性值,从而spring容器初始化失败。而我的properties文件是在springmvc的配置文件加载的,在springmvc的容器中会存在这些properties属性值,在springmvc中配置了我的控制器controller的扫描,那么该容器实例化我们的控制器会将属性注入到对象中。

怎样解决呢,就是在spring配置中不用让它去实例化我们的cotroller,只让springmvc实例化就可以了。 
所以在springmvc扫描包直接这样

<context:component-scan base-package="com.crm.controller"/>

在spring配置文件中不要扫描controller这个包即可。

Could not resolve placeholder 'CUST_INDUSTORY' in string value "${CUST_INDUSTORY}"的更多相关文章

  1. spring错误<context:property-placeholder>:Could not resolve placeholder XXX in string value XXX

    spring同时集成redis和mongodb时遇到多个资源文件加载的问题 这两天平台中集成redis和mongodb遇到一个问题 单独集成redis和单独集成mongodb时都可以正常启动程序,但是 ...

  2. spring错误:<context:property-placeholder>:Could not resolve placeholder XXX in string value XXX

    spring同时集成redis和mongodb时遇到多个资源文件加载的问题 这两天平台中集成redis和mongodb遇到一个问题 单独集成redis和单独集成mongodb时都可以正常启动程序,但是 ...

  3. Could not resolve placeholder 'IMAGE_SERVER_URL' in string value "${IMAGE_SERVER_URL}"

    这种问题 在网上查的是说使用了重复的property-placeholder   可能是在别的xml 也用了property-placeholder 解决方法 加上  ignore-unresolva ...

  4. Could not resolve placeholder'XXX' in string value "XXXX"

    练习SSM项目的demo中遇到一个问题,我在applicationContext.xml中使用了<context:property-placeholder location="clas ...

  5. spring cloud config---Could not resolve placeholder 'xxx' in string value "${xxx}"

    初学SpringCloud 跟着视频写配置 前前后后检查了许久,配置代码没问题 最后发现是client项目的配置文件名有问题,不应该是application.yml 而是bootstrap.yml 那 ...

  6. Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"

    1.启动dubbo的引用dubbo服务时候报下面这个错误,这是由于去找dubbo的发布服务未找到报的错误,所以先启动dubbo的发布服务即可. [INFO] Scanning for projects ...

  7. websphere启动报:Could not resolve placeholder 'hibernate.hbm2ddl.auto' in string value "${hibernate.hbm2ddl.auto}"

    websphere启动报/WEB-INF/applicationContext-orm- hibernate.xml]: Could not resolve placeholder 'hibernat ...

  8. Could not resolve placeholder

    使用spring的<context:property-placeholder location="/WEB-INF/redis.properties"/>读取prope ...

  9. Spring @Value注入值失败,错误信息提示:Could not resolve placeholder

    问题根源: @Value("${wx.app.config.appid}") public Object appid; 异常信息: Caused by: java.lang.Ill ...

随机推荐

  1. gcc 4步编译过程

    一. gcc编译过程  1. 预处理: 主要进行宏替换以及头文件的展开  gcc  -E   *.c  -o  *.i 2.  编译::编译生成汇编文件,会检查语法错误   gcc  -S   *.i ...

  2. 2000w数据,redis中只存20w的数据,如何保证redis中的数据都是热点数据

    redis 内存数据集大小上升到一定大小的时候,就会施行数据淘汰策略.redis 提供 6种数据淘汰策略: voltile-lru:从已设置过期时间的数据集(server.db[i].expires) ...

  3. .net下MVC中使用Tuple分页查询数据

    主要是在DAL层写查询分页的代码. 例如DAL层上代码: public Tuple<List<WxBindDto>, int> GetMbersInfo(int start, ...

  4. mysql 查询当前日期

    1.本年份 SELECT DATE_FORMAT(NOW(), '%Y'); 2.本月份(显示数字) SELECT DATE_FORMAT(NOW(), '%m'); 3.本月份(显示英文) SELE ...

  5. day25 模块,sys, logging, json, pickle

      Python之路,Day13 = Python基础13 sys模块 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0) sy ...

  6. Linux的命令提示符 修改

    Linux的命令提示符可按个人喜好随意更改,修改PS1的值即可: 在Ubuntu下若只是个别用户下修改~/.profile文件就好,所有用户统一则修改/etc/profile: 加入: export ...

  7. 树形dp——cf1092F

    被傻逼题降智了.. 就是第一次dfs 时 求一次size,一次deep数组 然后第二次dfs时直接求最大值 先把结点1的值求出来, u->v过程中,v子树的所有结点深度-1,v外的所有结点深度+ ...

  8. Font Awesome 完全兼容 Bootstrap 的所有组件。

    "F_FullName": "其他", "F_Icon": "glyphicon glyphicon-backward fa-lg ...

  9. final、static、package、import,和内部类、代码块总结

    final: final是最终修饰符,可以修饰类.成员方法.变量 final修饰的类无法被继承 final修饰的方法无法被重写 final修饰的变量无法被再次赋值,变为了常量 final修饰的引用数据 ...

  10. 03_mybatis配置文件详解

    1. SqlMapConfig.xml mybatis全局配置文件SqlMapConfig.xml,配置内容如下: *properties(属性) setting(全局配置参数) typeAliase ...