Ⅰ spring配置文件中的数据库用户名和密码怎么加密
一般spring容器启动时,通过PropertyPlaceholderConfigurer类读取jdbc.properties文件里的数据库配置信息。
通过这个原理,我们把加密后的数据库配置信息放到jdbc.properties文件里,然后自定义一个继承PropertyPlaceholderConfigurer的类重写processProperties方法,实现解密,把解密后的信息又放回去。
Ⅱ 如何学习spring cloud
Spring Cloud 学习笔记(一)——入门、特征、配置
0 放在前面
0.1 参考文档
http://cloud.spring.io/spring-cloud-static/Brixton.SR7/
https://springcloud.cc/
http://projects.spring.io/spring-cloud/
0.2 maven配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
0.3 简介
Spring Cloud为开发人员提供了快速构建分布式系统中的一些通用模式(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁,领导选举,分布式 会话,群集状态)。 分布式系统的协调引出样板模式(boiler plate patterns),并且使用Spring Cloud开发人员可以快速地实现这些模式来启动服务和应用程序。 它们可以在任何分布式环境中正常工作,包括开发人员自己的笔记本电脑,裸机数据中心和受管平台,如Cloud Foundry。
Version: Brixton.SR7
1 特征
Spring Cloud专注于为经典用例和扩展机制提供良好的开箱即用
分布式/版本配置
服务注册与发现
路由选择
服务调用
负载均衡
熔断机制
全局锁
领导人选举和集群状态
分布式消息
2 原生云应用程序
原生云是应用程序开发的一种风格,鼓励在持续交付和价值驱动领域的最佳实践。
Spring Cloud的很多特性是基于Spring Boot的。更多的是由两个库实现:Spring Cloud Context and Spring Cloud Commons。
2.1 Spring Cloud Context: 应用上下文服务
Spring Boot关于使用Spring构建应用有硬性规定:通用的配置文件在固定的位置,通用管理终端,监控任务。建立在这个基础上,Spring Cloud增加了一些额外的特性。
2.1.1 引导应用程序上下文
Spring Cloud会创建一个“bootstrap”的上下文,这是主应用程序的父上下文。对应的配置文件拥有最高优先级,并且,默认不能被本地配置文件覆盖。对应的文件名bootstrap.yml或bootstrap.properties。
可通过设置spring.cloud.bootstrap.enabled=false来禁止bootstrap进程。
2.1.2 应用上下文层级结构
当用SpringApplication或SpringApplicationBuilder创建应用程序上下文时,bootstrap上下文将作为父上下文被添加进去,子上下文将继承父上下文的属性。
子上下文的配置信息可覆盖父上下文的配置信息。
2.1.3 修改Bootstrap配置文件位置
spring.cloud.bootstrap.name(默认是bootstrap),或者spring.cloud.bootstrap.location(默认是空)
2.1.4 覆盖远程配置文件的值
spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false
2.1.5 定制Bootstrap配置
在/META-INF/spring.factories的key为org.springframework.cloud.bootstrap.BootstrapConfiguration,定义了Bootstrap启动的组件。
在主应用程序启动之前,一开始Bootstrap上下文创建在spring.factories文件中的组件,然后是@Beans类型的bean。
2.1.6 定制Bootstrap属性来源
关键点:spring.factories、PropertySourceLocator
2.1.7 环境改变
应用程序可通过EnvironmentChangedEvent监听应用程序并做出响应。
2.1.8 Refresh Scope
Spring的bean被@RefreshScope将做特殊处理,可用于刷新bean的配置信息。
注意
需要添加依赖“org.springframework.boot.spring-boot-starter-actuator”
目前我只在@Controller测试成功
需要自己发送POST请求/refresh
修改配置文件即可
2.1.9 加密和解密
Spring Cloud可对配置文件的值进行加密。
如果有"Illegal key size"异常,那么需要安装JCE。
2.1.10 服务点
除了Spring Boot提供的服务点,Spring Cloud也提供了一些服务点用于管理,注意都是POST请求
/env:更新Environment、重新绑定@ConfigurationProperties跟日志级别
/refresh重新加载配置文件,刷新标记@RefreshScope的bean
/restart重启应用,默认不可用
生命周期方法:/pause、/resume
2.2 Spring Cloud Commons:通用抽象
服务发现、负载均衡、熔断机制这种模式为Spring Cloud客户端提供了一个通用的抽象层。
2.2.1 RestTemplate作为负载均衡客户端
通过@Bean跟@LoadBalanced指定RestTemplate。注意URI需要使用虚拟域名(如服务名,不能用域名)。
如下:
@Configuration
public class MyConfiguration {
@LoadBalanced
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
}
public class MyClass {
@Autowired
private RestTemplate restTemplate;
public String doOtherStuff() {
String results = restTemplate.getForObject("http://stores/stores", String.class);
return results;
}
}
2.2.2 多个RestTemplate对象
注意@Primary注解的使用。
@Configuration
public class MyConfiguration {
@LoadBalanced
@Bean
RestTemplate loadBalanced() {
return new RestTemplate();
}
@Primary
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
}
public class MyClass {
@Autowired
private RestTemplate restTemplate;
@Autowired
@LoadBalanced
private RestTemplate loadBalanced;
public String doOtherStuff() {
return loadBalanced.getForObject("http://stores/stores", String.class);
}
public String doStuff() {
return restTemplate.getForObject("http://example.com", String.class);
}
}
2.2.3 忽略网络接口
忽略确定名字的服务发现注册,支持正则表达式配置。
3 Spring Cloud Config
Spring Cloud Config提供服务端和客户端在分布式系统中扩展配置。支持不同环境的配置(开发、测试、生产)。使用Git做默认配置后端,可支持配置环境打版本标签。
3.1 快速开始
可通过IDE运行或maven运行。
默认加载property资源的策略是克隆一个git仓库(at spring.cloud.config.server.git.uri')。
HTTP服务资源的构成:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
application是SpringApplication的spring.config.name,(一般来说'application'是一个常规的Spring Boot应用),profile是一个active的profile(或者逗号分隔的属性列表),label是一个可选的git标签(默认为"master")。
3.1.1 客户端示例
创建以Spring Boot应用即可,添加依赖“org.springframework.cloud:spring-cloud-starter-config”。
配置application.properties,注意URL为配置服务端的地址
spring.cloud.config.uri: http://myconfigserver.com
3.2 Spring Cloud Config 服务端
针对系统外的配置项(如name-value对或相同功能的YAML内容),该服务器提供了基于资源的HTTP接口。使用@EnableConfigServer注解,该服务器可以很容易的被嵌入到Spring Boot 系统中。使用该注解之后该应用系统就是一个配置服务器。
@SpringBootApplication
@EnableConfigServer
public class ConfigApplicion {
public static void main(String[] args) throws Exception {
SpringApplication.run(ConfigApplicion.class, args);
}
}
3.2.1 资源库环境
{application} 对应客户端的"spring.application.name"属性
{profile} 对应客户端的 "spring.profiles.active"属性(逗号分隔的列表)
{label} 对应服务端属性,这个属性能标示一组配置文件的版本
如果配置库是基于文件的,服务器将从application.yml和foo.yml中创建一个Environment对象。高优先级的配置优先转成Environment对象中的PropertySource。
3.2.1.1 Git后端
默认的EnvironmentRepository是用Git后端进行实现的,Git后端对于管理升级和物理环境是很方便的,对审计配置变更也很方便。也可以file:前缀从本地配置库中读取数据。
这个配置库的实现通过映射HTTP资源的{label}参数作为git label(提交id,分支名称或tag)。如果git分支或tag的名称包含一个斜杠 ("/"),此时HTTP URL中的label需要使用特殊字符串"(_)"来替代(为了避免与其他URL路径相互混淆)。如果使用了命令行客户端如 curl,请谨慎处理URL中的括号(例如:在shell下请使用引号''来转义它们)。
Git URI占位符
Spring Cloud Config Server支持git库URL中包含针对{application}和 {profile}的占位符(如果你需要,{label}也可包含占位符, 不过要牢记的是任何情况下label只指git的label)。所以,你可以很容易的支持“一个应用系统一个配置库”策略或“一个profile一个配置库”策略。
模式匹配和多资源库
spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
simple: https://github.com/simple/config-repo
special:
pattern: special*/dev*,*special*/dev*
uri: https://github.com/special/config-repo
local:
pattern: local*
uri: file:/home/configsvc/config-repo
如果 {application}/{profile}不能匹配任何表达式,那么将使用“spring.cloud.config.server.git.uri”对应的值。在上例子中,对于 "simple" 配置库, 匹配模式是simple/* (也就说,无论profile是什么,它只匹配application名称为“simple”的应用系统)。“local”库匹配所有application名称以“local”开头任何应用系统,不管profiles是什么(来实现覆盖因没有配置对profile的匹配规则,“/*”后缀会被自动的增加到任何的匹配表达式中)。
Git搜索路径中的占位符
spring.cloud.config.server.git.searchPaths
3.2.1.2 版本控制后端文件系统使用
伴随着版本控制系统作为后端(git、svn),文件都会被check out或clone 到本地文件系统中。默认这些文件会被放置到以config-repo-为前缀的系统临时目录中。在Linux上,譬如应该是/tmp/config-repo-<randomid>目录。有些操作系统routinely clean out放到临时目录中,这会导致不可预知的问题出现。为了避免这个问题,通过设置spring.cloud.config.server.git.basedir或spring.cloud.config.server.svn.basedir参数值为非系统临时目录。
3.2.1.3 文件系统后端
使用本地加载配置文件。
需要配置:spring.cloud.config.server.native.searchLocations跟spring.profiles.active=native。
路径配置格式:classpath:/, classpath:/config,file:./, file:./config。
3.2.1.4 共享配置给所有应用
基于文件的资源库
在基于文件的资源库中(i.e. git, svn and native),这样的文件名application*命名的资源在所有的客户端都是共享的(如 application.properties, application.yml, application-*.properties,etc.)。
属性覆盖
“spring.cloud.config.server.overrides”添加一个Map类型的name-value对来实现覆盖。
例如
spring:
cloud:
config:
server:
overrides:
foo: bar
会使所有的配置客户端应用程序读取foo=bar到他们自己配置参数中。
3.2.2 健康指示器
通过这个指示器能够检查已经配置的EnvironmentRepository是否正常运行。
通过设置spring.cloud.config.server.health.enabled=false参数来禁用健康指示器。
3.2.3 安全
你可以自由选择任何你觉得合理的方式来保护你的Config Server(从物理网络安全到OAuth2 令牌),同时使用Spring Security和Spring Boot 能使你做更多其他有用的事情。
为了使用默认的Spring Boot HTTP Basic 安全,只需要把Spring Security 增加到classpath中(如org.springframework.boot.spring-boot-starter-security)。默认的用户名是“user”,对应的会生成一个随机密码,这种情况在实际使用中并没有意义,一般建议配置一个密码(通过 security.user.password属性进行配置)并对这个密码进行加密。
3.2.4 加密与解密
如果远程属性包含加密内容(以{cipher}开头),这些值将在通过HTTP传递到客户端之前被解密。
使用略
3.2.5 密钥管理
配置服务可以使用对称(共享)密钥或者非对称密钥(RSA密钥对)。
使用略
3.2.6 创建一个测试密钥库
3.2.7 使用多密钥和循环密钥
3.2.8 加密属性服务
3.3 可替换格式服务
配置文件可加后缀".yml"、".yaml"、".properties"
3.4 文本解释服务
/{name}/{profile}/{label}/{path}
3.5 嵌入配置服务器
一般配置服务运行在单独的应用里面,只要使用注解@EnableConfigServer即可嵌入到其他应用。
3.6 推送通知和总线
添加依赖spring-cloud-config-monitor,激活Spring Cloud 总线,/monitor端点即可用。
当webhook激活,针对应用程序可能已经变化了的,配置服务端将发送一个RefreshRemoteApplicationEvent。
3.7 客户端配置
3.7.1 配置第一次引导
通过spring.cloud.config.uri属性配置Config Server地址
3.7.2 发现第一次引导
如果用的是Netflix,则用eureka.client.serviceUrl.defaultZone进行配置。
3.7.3 配置客户端快速失败
在一些例子里面,可能希望在没有连接配置服务端时直接启动失败。可通过spring.cloud.config.failFast=true进行配置。
3.7.4 配置客户端重试
添加依赖spring-retry、spring-boot-starter-aop,设置spring.cloud.config.failFast=true。默认的是6次重试,初始补偿间隔是1000ms,后续补偿为1.1指数乘数,可通过spring.cloud.config.retry.*配置进行修改。
3.7.5 定位远程配置资源
路径:/{name}/{profile}/{label}
"name" = ${spring.application.name}
"profile" = ${spring.profiles.active} (actually Environment.getActiveProfiles())
"label" = "master"
label对于回滚到之前的版本很有用。
3.7.6 安全
通过spring.cloud.config.password、spring.cloud.config.username进行配置。
Ⅲ SpringBoot连接MySQL数据库报错,弄了一下午求帮助
如果你是自己的服务器,请先检查用户名、密码是否完全正确
如果你是空间用户,请查看数据库IP和空间IP是否一致,如果不一致,数据库主机:
localhost
这里请填写数据库的IP,然后检查用户名和密码是否完全正确
Ⅳ spring boot调用加密狗
java开发加密狗的应用程序,应用于web项目。
springboot项目加密解决方案:配置pomxml用maven直接构建加密后的jar包。使用maven构建jar包;如果springboot项目使用到了JPA并且是用hibernate实现的,那么启动加密后的jar是会报错的,创建服务命令:管理员进入cmd输入 WinSWNET,exe install 即可创建服务;启动服务即可。
"加密锁"(也称加密狗)最早由彩虹天地开发,现已成为软件加密行业的代名词。加密锁是为软件开发商提供的一种智能型的具有软件保护功能的工具,它包含一个安装在计算机并行口或 USB 口上的硬件,及一套适用于各种语言的接口软件和工具软件。加密锁基于硬件保护技术,其目的是通过对软件与数据的保护防止知识产权被非法使用。
Ⅳ springboot上传文件到服务器aes加密
业务需求:数据库中的用户名密码明文存储在配置文件中,不是十分安全。所以将数据库中的用户名密码使用AES对称加密放入配置文件中,达到加密效果。同时也不想使用tomcat等中间件等太繁重,就使用了spring boot 轻量级框架。个人比较菜,轻喷。
关于如何搭建spring boot项目其他的人说的很详细 参考初识Spring Boot框架
入口类代码
@Controller
@SpringBootApplication
@EnableAutoConfiguration
{
publicstaticvoidmain(String[]args){
SpringApplication.run(Aesdemo1Application.class,args);
}
}
运行时只要运行main方法 或者打包后java -jar 即可(写成.bat文件 点击运行方便简单)
@Controller
publicclassGetKeyController{
@GetMapping("/getkey")
publicStringgreetingForm(Modelmodel){
model.addAttribute("passwordBean",newPasswordBean());return"index";
}
@PostMapping("/getkey")
publicStringgreetingSubmit(@){
Strings1=AESUtil.encrypt(passwordBean.getPassword(),passwordBean.getVar1());
passwordBean.setVar2(s1);
return"result";
}
}
启动后有这里还有一个控制器类
浏览器地址输入 http://localhost:8080/getkey 即可跳转到greetingForm 方法,赋入PasswordBean属性后 跳转到index.html
PasswordBean 是自己定义的bean类 里面有password var1 var2 3个属性
index.html代码
<!DOCTYPEhtml>
<htmllang="en"xmlns:th="http://www.thymeleaf.org">
<head>
<metacharset="UTF-8"/>
<title>Title</title>
</head>
<body>
<formaction="#"th:action="@{/getkey}"th:object="${passwordBean}"method="post">
<p>密码:<inputtype="text"th:field="*{password}"/></p>
<p>加密字符:<inputtype="text"th:field="*{var1}"/></p>
<p><inputtype="submit"value="Submit"/>
<inputtype="reset"value="Reset"/></p>
</form>
</body>
</html>
注意使用了thymeleaf框架 所以必须引入
输入要加密的和盐即可获得通过post方法到result即可获得加密后字符串
<!DOCTYPEhtml>
<htmllang="en"xmlns:th="http://www.thymeleaf.org">
<head>
<metacharset="UTF-8"/>
<title>Title</title>
</head>
<body>
<h1>Result</h1>
<pth:text="'密码:'+${passwordBean.password}"/>
<pth:text="'加密字符:'+${passwordBean.var1}"/>
<pth:text="'加密后字符:'+${passwordBean.var2}"/>
<ahref="/getkey">Submitanothermessage</a>
</body>
</html>
Ⅵ springboot feignclient调用服务请求参数加密
spring boot配置(1) 作者同类文章X <dependency> <groupId>org.springframework...如调用网络的一个api @FeignClient(url = "${map.url}",name
Ⅶ 大神们有谁知道springboot里面运行的tomcat的用户名和密码
springboot运行好像是默认配置的tomcat。tomcat的管理者才有密码这个,密码在tomcat-user.xml文件中。
Ⅷ spring cloud 本地配置怎么自动部署
Spring Cloud 习笔记()——入门、特征、配置
0 放前面
0.1 参考文档
0.2 maven配置
org.springframework.boot
spring-boot-starter-parent
1.5.2.RELEASE
org.springframework.cloud
spring-cloud-dependencies
Dalston.RELEASE
pom
import
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-starter-eureka
0.3 简介
Spring Cloud发员提供快速构建布式系统些通用模式(例配置管理服务发现断路器智能路由微代理控制总线性令牌全局锁领导选举布式 群集状态) 布式系统协调引板模式(boiler plate patterns)并且使用Spring Cloud发员快速实现些模式启服务应用程序 任何布式环境工作包括发员自笔记本电脑裸机数据受管平台Cloud Foundry
Version: Brixton.SR7
1 特征
Spring Cloud专注于经典用例扩展机制提供良箱即用
布式/版本配置
服务注册与发现
路由选择
服务调用
负载均衡
熔断机制
全局锁
领导选举集群状态
布式消息
2 原云应用程序
原云应用程序发种风格鼓励持续交付价值驱领域佳实践
Spring Cloud特性基于Spring Boot更由两库实现:Spring Cloud Context and Spring Cloud Commons
2.1 Spring Cloud Context: 应用文服务
Spring Boot关于使用Spring构建应用硬性规定:通用配置文件固定位置通用管理终端监控任务建立基础Spring Cloud增加些额外特性
2.1.1 引导应用程序文
Spring Cloud创建bootstrap文主应用程序父文应配置文件拥高优先级并且默认能本配置文件覆盖应文件名bootstrap.yml或bootstrap.properties
通设置spring.cloud.bootstrap.enabled=false禁止bootstrap进程
2.1.2 应用文层级结构
用SpringApplication或SpringApplicationBuilder创建应用程序文bootstrap文作父文添加进文继承父文属性
文配置信息覆盖父文配置信息
2.1.3 修改Bootstrap配置文件位置
spring.cloud.bootstrap.name(默认bootstrap)或者spring.cloud.bootstrap.location(默认空)
2.1.4 覆盖远程配置文件值
spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false
2.1.5 定制Bootstrap配置
/META-INF/spring.factorieskeyorg.springframework.cloud.bootstrap.BootstrapConfiguration定义Bootstrap启组件
主应用程序启前始Bootstrap文创建spring.factories文件组件@Beans类型bean
2.1.6 定制Bootstrap属性源
关键点:spring.factories、PropertySourceLocator
2.1.7 环境改变
应用程序通EnvironmentChangedEvent监听应用程序并做响应
2.1.8 Refresh Scope
Springbean@RefreshScope做特殊处理用于刷新bean配置信息
注意
需要添加依赖org.springframework.boot.spring-boot-starter-actuator
目前我@Controller测试功
需要自发送POST请求/refresh
修改配置文件即
2.1.9 加密解密
Spring Cloud配置文件值进行加密
"Illegal key size"异需要安装JCE
2.1.10 服务点
除Spring Boot提供服务点Spring Cloud提供些服务点用于管理注意都POST请求
/env:更新Environment、重新绑定@ConfigurationProperties跟志级别
/refresh重新加载配置文件刷新标记@RefreshScopebean
/restart重启应用默认用
命周期:/pause、/resume
2.2 Spring Cloud Commons:通用抽象
服务发现、负载均衡、熔断机制种模式Spring Cloud客户端提供通用抽象层
2.2.1 RestTemplate作负载均衡客户端
通@Bean跟@LoadBalanced指定RestTemplate注意URI需要使用虚拟域名(服务名能用域名)
:
@Configuration
public class MyConfiguration {
@LoadBalanced
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
}
public class MyClass {
@Autowired
private RestTemplate restTemplate;
public String doOtherStuff() {
String results = restTemplate.getForObject("", String.class);
return results;
}
}
2.2.2 RestTemplate象
注意@Primary注解使用
@Configuration
public class MyConfiguration {
@LoadBalanced
@Bean
RestTemplate loadBalanced() {
return new RestTemplate();
}
@Primary
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
}
public class MyClass {
@Autowired
private RestTemplate restTemplate;
@Autowired
@LoadBalanced
private RestTemplate loadBalanced;
public String doOtherStuff() {
return loadBalanced.getForObject("", String.class);
}
public String doStuff() {
return restTemplate.getForObject("", String.class);
}
}
2.2.3 忽略网络接口
忽略确定名字服务发现注册支持则表达式配置
3 Spring Cloud Config
Spring Cloud Config提供服务端客户端布式系统扩展配置支持同环境配置(发、测试、产)使用Git做默认配置端支持配置环境打版本标签
3.1 快速始
通IDE运行或maven运行
默认加载property资源策略克隆git仓库(at spring.cloud.config.server.git.uri')
HTTP服务资源构:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
.config.name,(般说'application'规Spring Boot应用),profileactiveprofile(或者逗号隔属性列表),label选git标签(默认"master")
3.1.1 客户端示例
创建Spring Boot应用即添加依赖org.springframework.cloud:spring-cloud-starter-config
配置application.properties注意URL配置服务端址
spring.cloud.config.uri:
3.2 Spring Cloud Config 服务端
针系统外配置项(name-value或相同功能YAML内容),该服务器提供基于资源HTTP接口使用@EnableConfigServer注解,该服务器容易嵌入Spring Boot 系统使用该注解该应用系统配置服务器
@SpringBootApplication
@EnableConfigServer
public class ConfigApplicion {
public static void main(String[] args) throws Exception {
SpringApplication.run(ConfigApplicion.class, args);
}
}
3.2.1 资源库环境
{application} 应客户端"spring.application.name"属性
{profile} 应客户端 "spring.profiles.active"属性(逗号隔列表)
{label} 应服务端属性,属性能标示组配置文件版本
配置库基于文件服务器application.ymlfoo.yml创建Environment象高优先级配置优先转Environment象PropertySource
3.2.1.1 Git端
默认EnvironmentRepository用Git端进行实现Git端于管理升级物理环境便,审计配置变更便file:前缀本配置库读取数据
配置库实现通映射HTTP资源{label}参数作git label(提交id,支名称或tag)git支或tag名称包含斜杠 ("/"),HTTP URLlabel需要使用特殊字符串"(_)"替代(避免与其URL路径相互混淆)使用命令行客户端 curl请谨慎处理URL括号(例:shell请使用引号''转义)
Git URI占位符
Spring Cloud Config Server支持git库URL包含针{application} {profile}占位符(需要,{label}包含占位符, 要牢记任何情况label指gitlabel)所容易支持应用系统配置库策略或profile配置库策略
模式匹配资源库
spring:
cloud:
config:
server:
git:
uri:
repos:
simple:
special:
pattern: special*/dev*,*special*/dev*
uri:
local:
pattern: local*
uri: file:/home/configsvc/config-repo
{application}/{profile}能匹配任何表达式使用spring.cloud.config.server.git.uri应值例于 "simple" 配置库, 匹配模式simple/* (说,论profile匹配application名称simple应用系统)local库匹配所application名称local任何应用系统管profiles(实现覆盖没配置profile匹配规则/*缀自增加任何匹配表达式)
Git搜索路径占位符
spring.cloud.config.server.git.searchPaths
3.2.1.2 版本控制端文件系统使用
伴随着版本控制系统作端(git、svn)文件都check out或clone 本文件系统默认些文件放置config-repo-前缀系统临目录Linux譬应该/tmp/config-repo-目录些操作系统routinely clean out放临目录导致预知问题现避免问题通设置spring.cloud.config.server.git.basedir或spring.cloud.config.server.svn.basedir参数值非系统临目录
3.2.1.3 文件系统端
使用本加载配置文件
需要配置:spring.cloud.config.server.native.searchLocations跟spring.profiles.active=native
路径配置格式:classpath:/, classpath:/config,file:./, file:./config
3.2.1.4 共享配置给所应用
基于文件资源库
基于文件资源库(i.e. git, svn and native)文件名application*命名资源所客户端都共享( application.properties, application.yml, application-*.properties,etc.)
属性覆盖
spring.cloud.config.server.overrides添加Map类型name-value实现覆盖
例
spring:
cloud:
config:
server:
overrides:
foo: bar
使所配置客户端应用程序读取foo=bar自配置参数
3.2.2 健康指示器
通指示器能够检查已经配置EnvironmentRepository否运行
通设置spring.cloud.config.server.health.enabled=false参数禁用健康指示器
3.2.3 安全
自由选择任何觉合理式保护Config Server(物理网络安全OAuth2 令牌)同使用Spring SecuritySpring Boot 能使做更其用事情
使用默认Spring Boot HTTP Basic 安全需要Spring Security 增加classpath(org.springframework.boot.spring-boot-starter-security)默认用户名user应随机密码种情况实际使用并没意义般建议配置密码(通 security.user.password属性进行配置)并密码进行加密
3.2.4 加密与解密
远程属性包含加密内容({cipher}),些值通HTTP传递客户端前解密
使用略
3.2.5 密钥管理
配置服务使用称(共享)密钥或者非称密钥(RSA密钥)
使用略
3.2.6 创建测试密钥库
3.2.7 使用密钥循环密钥
3.2.8 加密属性服务
3.3 替换格式服务
配置文件加缀".yml"、".yaml"、".properties"
3.4 文本解释服务
/{name}/{profile}/{label}/{path}
3.5 嵌入配置服务器
般配置服务运行单独应用面要使用注解@EnableConfigServer即嵌入其应用
3.6 推送通知总线
添加依赖spring-cloud-config-monitor激Spring Cloud 总线/monitor端点即用
webhook激针应用程序能已经变化配置服务端发送RefreshRemoteApplicationEvent
3.7 客户端配置
3.7.1 配置第引导
通spring.cloud.config.uri属性配置Config Server址
3.7.2 发现第引导
用Netflix则用eureka.client.serviceUrl.defaultZone进行配置
3.7.3 配置客户端快速失败
些例面能希望没连接配置服务端直接启失败通spring.cloud.config.failFast=true进行配置
3.7.4 配置客户端重试
添加依赖spring-retry、spring-boot-starter-aop设置spring.cloud.config.failFast=true默认6重试初始补偿间隔1000ms续补偿1.1指数乘数通spring.cloud.config.retry.*配置进行修改
3.7.5 定位远程配置资源
路径:/{name}/{profile}/{label}
"name" = ${spring.application.name}
"profile" = ${spring.profiles.active} (actually Environment.getActiveProfiles())
"label" = "master"
label于滚前版本用
3.7.6 安全
通spring.cloud.config.password、spring.cloud.config.username进行配置
Ⅸ springboot怎么做统一的权限控制
先简单介绍一下Shiro,对于没有用过Shiro的朋友,也算是做个简介吧。
Shiro是Apache下的一个开源项目,我们称之为Apache Shiro。它是一个很易用与Java项目的的安全框架,提供了认证、授权、加密、会话管理,与 Spring Security 一样都是做一个权限的安全框架,但是与Spring Security 相比,在于 Shiro 使用了比较简单易懂易于使用的授权方式。
Ⅹ springboot application.properties 写多个配置文件怎么写
springboot application.properties 写多个配置文件的方法:
# 文件编码
banner.charset= UTF-8
# 文件位置
banner.location= classpath:banner.txt
# 日志配置
# 日志配置文件的位置。 例如对于Logback的`classpath:logback.xml`
logging.config=
# %wEx#记录异常时使用的转换字。
logging.exception-conversion-word=
# 日志文件名。 例如`myapp.log`
logging.file=
# 日志级别严重性映射。 例如`logging.level.org.springframework = DEBUG`
logging.level.*=
# 日志文件的位置。 例如`/ var / log
logging.path=
# 用于输出到控制台的Appender模式。 只支持默认的logback设置。
logging.pattern.console=
# 用于输出到文件的Appender模式。 只支持默认的logback设置。
logging.pattern.file=
# 日志级别的Appender模式(默认%5p)。 只支持默认的logback设置。
logging.pattern.level=
#注册日志记录系统的初始化挂钩。
logging.register-shutdown-hook= false
# AOP 切面
# 添加@EnableAspectJAutoProxy。
spring.aop.auto= true
# 是否要创建基于子类(CGLIB)的代理(true),而不是基于标准的基于Java接口的代理(false)。
spring.aop.proxy-target-class= false
# 应用程序上下文初始化器
# 应用指标。
spring.application.index=
# 应用程序名称。
spring.application.name=
# 国际化(消息源自动配置)
#
spring.messages.basename= messages
# 以逗号分隔的基础名称列表,每个都在ResourceBundle约定之后。
# 加载的资源束文件缓存到期,以秒为单位。 设置为-1时,软件包将永久缓存。
spring.messages.cache-seconds= -1
# 消息编码。
spring.messages.encoding= UTF-8
# 设置是否返回到系统区域设置,如果没有找到特定语言环境的文件。
spring.messages.fallback-to-system-locale= true
# REDIS (Redis 配置)
# 连接工厂使用的数据库索引。
spring.redis.database= 0
# Redis服务器主机。
spring.redis.host= localhost
# 登录redis服务器的密码。
spring.redis.password=
# 给定时间池可以分配的最大连接数。 使用负值为无限制。
spring.redis.pool.max-active= 8
# 池中“空闲”连接的最大数量。 使用负值来表示无限数量的空闲连接。
spring.redis.pool.max-idle= 8
# 连接分配在池耗尽之前在抛出异常之前应阻止的最大时间量(以毫秒为单位)。 使用负值无限期地阻止。
spring.redis.pool.max-wait= -1
# 定义池中维护的最小空闲连接数。 此设置只有在正值时才有效果。
spring.redis.pool.min-idle= 0
# redis服务器端口
spring.redis.port= 6379
# redis服务器名称
spring.redis.sentinel.master=
# spring.redis.sentinel.nodes=
# 连接超时(毫秒)。
spring.redis.timeout= 0
# 管理员 (Spring应用程序管理员JMX自动配置)
# 开启应用管理功能。
spring.application.admin.enabled= false
# JMX应用程序名称MBean。
spring.application.admin.jmx-name= org.springframework.boot:type= Admin,name= SpringApplication
# 自动配置
# 自动配置类排除。
spring.autoconfigure.exclude=
# spring 核心配置
# 跳过搜索BeanInfo类。
spring.beaninfo.ignore= true
# spring 缓存配置
# 由底层缓存管理器支持的要创建的缓存名称的逗号分隔列表。
spring.cache.cache-names=
# 用于初始化EhCache的配置文件的位置。
spring.cache.ehcache.config=
# 用于创建缓存的规范。 检查CacheBuilderSpec有关规格格式的更多细节。
spring.cache.guava.spec=
# 用于初始化Hazelcast的配置文件的位置。
spring.cache.hazelcast.config=
# 用于初始化Infinispan的配置文件的位置。
spring.cache.infinispan.config=
# 用于初始化缓存管理器的配置文件的位置。
spring.cache.jcache.config=
# 用于检索符合JSR-107的缓存管理器的CachingProvider实现的完全限定名称。 只有在类路径上有多个JSR-107实现可用时才需要。
spring.cache.jcache.provider=
# 缓存类型,默认情况下根据环境自动检测。
spring.cache.type=
# spring配置 (配置文件应用侦听器)
# 配置文件位置。
spring.config.location=
# 配置文件名。
spring.config.name= application