Could not resolve placeholder 'CUST_INDUSTORY' in string value "${CUST_INDUSTORY}"
来源:互联网 发布:南京四维星软件 编辑:程序博客网 时间:2024/06/06 16:27
问题描述
项目中的资源文件中写了个properties文件,内容这样的
CUST_FROM=002CUST_INDUSTORY=001CUST_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;@Controllerpublic 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这个包即可。
0 0
- Could not resolve placeholder 'CUST_INDUSTORY' in string value "${CUST_INDUSTORY}"
- $Value{}ntException: Could not resolve placeholder 'KEY' in string value "${
- Could not resolve placeholder 'driverClassName' in string value "${driverClassName}"
- Could not resolve placeholder 'driver' in string value "${driver}"
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- Could not resolve placeholder 'driverClasss' in string value "${driverClasss}"
- 解决 IllegalArgumentException: Could not resolve placeholder in string value "${XXXXXX}"
- Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}
- Could not resolve placeholder 'master.jdbc.url' in string value "${master.jdbc.url}"
- 解决 Could not resolve placeholder 'some.var.name' in string value
- Could not resolve placeholder 'spring.security.mapping.directory' in string value "${spring.security
- Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- 报错Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}
- Could not resolve placeholder 'redis.pool.maxTotal' in string value "${redis.pool.maxTotal}"
- Could not resolve placeholder 'jdbc.driverClassName' in string value "${jdbc.driverClassName}错误
- 错误笔记之Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"
- spring cloud config---Could not resolve placeholder 'foo' in string value "${foo}"
- Nginx的日志备份操作
- Java final 关键字
- Activity生命周期分析
- 我的开发常用工具类方法
- LinkedBlockingQueue的put,add跟offer的区别
- Could not resolve placeholder 'CUST_INDUSTORY' in string value "${CUST_INDUSTORY}"
- codevs1017 乘积最大 dfs 也可以dp
- JavaScript地图手动输入起始与终点位置搜索
- VMware中的网络设置问题
- 在Window下编译生成ffmpeg的动态链接库.dll文件
- Android studio 点.9图报错 ERROR: 9-patch image finished with non-zero exit value 42解决办法
- Nginx的日志管理
- 自动等待
- C# 分层开发的案例 学生管理系统 实现用户的登录和修改密码