使用Spring注解获取配置文件信息
需要加载的配置文件内容(resource.properties):
#FTP相关配置
#FTP的IP地址
FTP_ADDRESS=192.168.1.121
FTP_PORT=21
FTP_USERNAME=ftpuser
FTP_PASSWORD=root
FTP_BASE_PATH=/home/ftpuser/taotao/images #图片服务器的相关配置
#图片服务器的基础URL
IMAGE_BASE_URL=http://192.168.1.121/images
实现在applicationContext.xml中需要配置加载的配置文件:
<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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 加载配置文件 -->
<context:property-placeholder location="classpath:resource/*.properties" /> </beans>
然后使用注解方式获取配置文件中的信息:
package com.taotao.service.impl;
import com.taotao.service.PictureService; @Service
public class PictureServiceImpl implements PictureService
{
@Value("${FTP_ADDRESS}")
private String FTP_ADDRESS; @Value("${FTP_PORT}")
private Integer FTP_PORT; @Value("${FTP_USERNAME}")
private String FTP_USERNAME; @Value("${FTP_PASSWORD}")
private String FTP_PASSWORD; @Value("${FTP_BASE_PATH}")
private String FTP_BASE_PATH; @Value("${IMAGE_BASE_URL}")
private String IMAGE_BASE_URL; }
这样既可以使用配置文件中的字段了。
使用Spring注解获取配置文件信息的更多相关文章
- SpringBoot项目中,获取配置文件信息
1.在配置文件中设置信息,格式如下 wechat: mpAppId: wxdf2b09f280e6e6e2 mpAppSecret: f924b2e9f140ac98f9cb5317a8951c71 ...
- Spring Boot使用@Value注解获取配置文件中的属性
获取配置文件的内容——
- SpringBoot配置分析、获取到SpringBoot配置文件信息以及几种获取配置文件信息的方式
Spring入门篇:https://www.cnblogs.com/biehongli/p/10170241.html SpringBoot的默认的配置文件application.properties ...
- 获取配置文件信息——configparser
配置文件host.int格式如下: [host]product=xxxxxxxxxxtest=xxxxxxxxxx python 3.x代码如下: import os,configparser def ...
- .Net FrameWork获取配置文件信息
今天在做项目的时候需要到配置文件中读取信息,之前自己并没有操作过,今天算是完成自己的一个心愿.读取配置文件中的信息并不难,大致思路是: 1.载入配置文件,获取配置文件的实例. 2.获取配置文件的节点 ...
- mybatis整合spring获取配置文件信息出错
描述:mybatis整合spring加载jdbc.properties文件,然后使用里面配置的值来 配置数据源,后来发现用户变成了admin- jdbc.properties的配置: 加载配置: 报错 ...
- Spring MVC通过Pageable对象和PageableDefault注解获取分页信息(MongoDB通过Pageable来操作分页)
说明:Pageable同时也能用于操作MongoDB的分页. PageableSpring Data库中定义的一个接口,该接口是所有分页相关信息的一个抽象,通过该接口,我们可以得到和分页相关所有信息( ...
- Spring Boot使用@ConfigurationProperties注解获取配置文件中的属性值
注意:这种方式要提供属性的getter/setter方法—— 如果idea报错,提示没有相应的执行器,就需要在maven中添加: (虽然不配置代码也能正常运行,作用在下面会说明) 配置了该执行器后,在 ...
- Sping boot 之 @Value("${xxx}") 注解获取配置文件内容
1.注解方式读取 1-1.@PropertySource配置文件路径设置,在类上添加注解,如果在默认路径下可以不添加该注解. 需要用@PropertySource的有: 例如非application. ...
随机推荐
- 【openwrt+arduion】案例
http://www.geek-workshop.com/thread-4950-1-1.html http://www.guokr.com/article/319356/ http://www.gu ...
- ReactNative iOS源码解析
http://awhisper.github.io/2016/06/24/ReactNative%E6%B5%81%E7%A8%8B%E6%BA%90%E7%A0%81%E5%88%86%E6%9E% ...
- Hadoop1.2.1 单机模式安装
首先安装JDK: 然后安装hadoop: 最后的实例测试:首先在 /opt/data 目录下创建 input目录, 然后把hadoop的conf目录下的所有xml文件拷贝到上面的input目录, 然后 ...
- HashMap实现原理、核心概念、关键问题的总结
简单罗列一下较为重要的点: 同步的问题 碰撞处理问题 rehash的过程 put和get的处理过程 HashMap基础: HashMap的理论基础:维基百科哈希表 JDK中HashMap的描述:Has ...
- studio导入Eclipse 项目要改的文件
添加下面文件即可,一个不能少 1. project 2.project.properties 3.classpath 4.AndroidManifest.xml 以上目录都有可以正常导入studio中
- VC启动一个新线程的三种方法
第一种AfxBeginThread() 用AfxBeginThread()函数来创建一个新线程来执行任务,工作者线程的AfxBeginThread的原型如下: CWinThread* AfxBegin ...
- c++多线程例(互斥体,共同访问)
<pre name="code" class="cpp">//这是2个线程模拟卖火车票的小程序 #include <windows.h> ...
- handlebars Helper用法
handlebars Helper用法: http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471357.html 逻辑运算符在handle ...
- 【BZOJ3622】已经没有什么好害怕的了 容斥+DP
[BZOJ3622]已经没有什么好害怕的了 Description Input Output Sample Input 4 2 5 35 15 45 40 20 10 30 Sample Output ...
- dede标签:arclist标签使用大全
特别提示:arclist是织梦建站系统中最重要的标签,同时也是最基础的标签,希望大家熟练掌握,可以说是学习织梦必备知识. 标签名称:arclist标记简介:织梦常用标记,也称为自由列表标记,其中img ...