使用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. ... 
随机推荐
- 随机算法 - HNU 13348 Finding Lines
			Finding Lines Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13348&am ... 
- 在Asp.net中为图像加入水印信息
			using System.Drawing; using System.IO; using System.Drawing.Imaging; private void AddTextToImg(strin ... 
- 如何在ChemDraw中输入℃温度符号
			化学反应常常对于温度是有一定要求的,所以用ChemDraw化学绘图工具在绘制化学反应的时候常常会用到℃温度符号.但是一些才接触ChemDraw的用户朋友不知道怎么输入℃.针对这种情况本教程来给大家分享 ... 
- [ASK] brew install nginx
			.......... .......... Error: Permission denied - /usr/local/etc/openssl .......... .......... Cannot ... 
- php 快速读取文件夹下文件列表
			在读取某个文件夹下的内容的时候 以前是使用 opendir readdir结合while循环过滤 . ..当前文件夹和父文件夹来操作的. 代码如下: 然后偶然发现了有scandir函数 可以扫描文件夹 ... 
- vs 代码自动对其(注释,等号...)
			插件:Code alignment 下载地址 
- Javascript通过bind()掌控this
			Javascript通过bind()掌控this: http://blog.csdn.net/rznice/article/details/26134201 bind能为我们做些什么,同时它的好处在哪 ... 
- Android软键盘的隐藏显示研究
			http://winuxxan.blog.51cto.com/2779763/522810 全局推: android:windowSoftInputMode="adjustResize&qu ... 
- 面试之四:JVM内存区域分配
			1.程序计数器(线程私有)[不会OOM] 记录线程执行的代码位置,每个线程各自独有. 2.栈:虚拟机栈和本地方法栈(线程私有)[会OOM和StackOverflow] 虚拟机栈 每个JAVA方法在执行 ... 
- snappy性能测试之安装运行
			项目地址:https://code.google.com/p/snappy/ 下载后,解压. $./configure $make 建立一个简单的测试文件a.cpp: #include "s ... 
