zoukankan      html  css  js  c++  java
  • Spring3中用注解直接注入properties中的值

    在bean(可是controller, service, dao等了)中,使用@Value注解:

    @Service

    public class TestService{

    @Value("${sytem.username}")
    String loginUserName;

    }

    在spring中定义资源文件:
    <context:property-placeholder />或者org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <array>
    <value>classpath:config.properties</value>
    </array>
    </property>
    </bean>
    config.properties文件:

    sytem.username=admin

    这样config.properties中的sytem.username就注入到loginUserName属性中了
    我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他 们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其 实我是一个程序员
  • 相关阅读:
    [Hadoop]
    [Linux]
    [Linux]
    [Hadoop]
    [Hadoop]
    vue-学习笔记-API-全局配置
    vue 风格指南-必须的
    vue 学习笔记-复用-自定义指令
    vue学习笔记-过滤器
    vue 学习笔记-复用-对象混入
  • 原文地址:https://www.cnblogs.com/kms1989/p/5287706.html
Copyright © 2011-2022 走看看