springboot资源属性配置

资源文件中的属性配置与映射到实体类
demo/pom.xml

      <dependency>
			<groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>





添加资源文件
src/main/resources/resource.properties



com.oracle.opensource.name=oracle
com.oracle.opensource.website=www.oracle.com
com.oracle.opensource.language=java
com.oracle.pojo/Resource.java










package com.oracle.pojo;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@ConfigurationProperties(prefix="com.oracle.opensource")
@PropertySource(value="classpath:resource.properties")
public class Resource {
	private String name;
	private String website;
	private String language;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getWebsite() {
		return website;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
	}
}






com.oracle.controller/HelloContoller.java




package com.oracle.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.oracle.pojo.IMoocJSONResult;
import com.oracle.pojo.Resource;

@RestController
public class HelloContoller {

	@Autowired
	private Resource resource;
	
	@RequestMapping("/getResource")
	public IMoocJSONResult getResource() {
		
		Resource bean = new Resource();
		BeanUtils.copyProperties(resource, bean);
		
		return IMoocJSONResult.ok(bean);
	}
	
}

测试

一、 SpringBoot资源文件配置server以及tomcat
src/main/resources/application.properties.java

############################################################
#
# Server 服务端配置
#
############################################################
#配置端口号
#server.port=8080
#配置context-path,这个配置在正式发布时不需要配置。
#server.context-path=/IMooc
#错误页,指定发生错误时,跳转的URL
#server.error.path=/error
#session最大超时时间,默认为30分钟
server.session-timeout=30
#该服务绑定的IP地址
#server.address=192.168.1.2

############################################################
# Server - tomcat 相关配置
############################################################
#tomcat最大线程数,默认为200
#server.tomcat.max-threads=250
#tomcat的URI编码
server.tomcat.uri-encoding=UTF-8
#存放tomcat的日志,dump文件的临时文件夹,默认为系统的tmp文件夹。
#如: C:\Users\Shanhy\AppData\Local\Temp
#server.tomcat.basedir=H:/springboot-tomcat-tmp
#打开tomcat的Access日志,并可以设置日志格式的方法。
#server.tomcat.access-log-enabled=true
#server.tomcat.access-log-pattern=
# accesslog目录,默认在basedir/logs
#server.tomcat.accesslog.directory=
#日志文件目录
#logging.path=H:/springboot-tomcat-tmp
#日志文件名,默认为spring.log
#logging.file=myapp.log
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值