springmvc 属性放数据库中解决方法 以及 @Controller 中 使用@vlaue无法注入属性值问题详解

springmvc  属性放数据库中解决方法 
    自定义一个DatabaseProperties extends PropertyPlaceholderConfigurer implements ApplicationContextAware
    重写 mergeProperties 方法 加载数据库的配置 生成新的  Properties 类返回
    ==》 applicationContext.xml文件中配置  如果要在@controller中使用  
            @vlaue 注入属性值  就需要在默认的  spring-servlet.xml中也配置以下配置
    <!-- 这里不能用${} -->
   <bean id="dataBaseProperties" class="com.sfiec.oms.common.DatabaseProperties">
<property name="order" value="2" />
<constructor-arg value="构造参数" />
   </bean>

@Controller 中 使用@vlaue无法注入属性值问题详解  转载 http://blog.csdn.net/arsenic/article/details/48287745
1, spring-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中是取不到的,必须在 spring-servlet.xml 中把获取属性文件再定义一下
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值