zoukankan      html  css  js  c++  java
  • 学习之spring属性文件注入

    package com.my.proper;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Component;
    
    @Component("configInfo")
    public class ConfigInfo {
        @Value("${pagesize}")
        private String pagesize;
    
        @Value("${aaa}")
        private String aaa;
    
        public String getAaa() {
            return aaa;
        }
    
        public void setAaa(String aaa) {
            this.aaa = aaa;
        }
    
        public String getPagesize() {
            return pagesize;
        }
    
        public void setPagesize(String pagesize) {
            this.pagesize = pagesize;
        }
    }
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util" xmlns:cache="http://www.springframework.org/schema/cache"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.2.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
        <context:component-scan base-package="com.my.proper" />
        <context:component-scan base-package="com.my.action" />
    
        <!-- spring的属性加载器,加载properties文件中的属性 -->
        <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:messages.properties</value>
                    <value>classpath:messages2.properties</value>
                </list>
            </property>
            <property name="fileEncoding" value="utf-8" />
        </bean>
    </beans>
        public void propertyTest() {
            ConfigInfo config = (ConfigInfo) cx.getBean("configInfo");
            System.out.println(config.getPagesize());
            System.out.println(config.getAaa());
        }

    有追求,才有动力!

    向每一个软件工程师致敬!

    by wujf

    mail:921252375@qq.com

  • 相关阅读:
    linux之SQL语句简明教程---主键,外来键
    [LeetCode][Java] Best Time to Buy and Sell Stock IV
    S3C2440 IIS操作 uda134x录放音
    Cocos2d-x 3.0 打造一个全平台概念文件夹
    Irrlicht 3D Engine 笔记系列之 教程4
    Swift----编程语言语法
    Nginx优化指南+LINUX内核优化+linux连接数优化+nginx连接数优化
    windows平台是上的sublime编辑远程linux平台上的文件
    POJ 2249-Binomial Showdown(排列组合计数)
    Linux 循环
  • 原文地址:https://www.cnblogs.com/wujf/p/5287903.html
Copyright © 2011-2022 走看看