springboot 学习笔记
1. application.yaml application.properties区别
2. java -jar ****.jar --spring.profiles.active=pro
3. 热部署 springboot-devtools complier ctrl+shift +alt +/
4. @Value("${value.common:123"}) yaml: value.common:${defaultStr:12345}
application.run(" ------value.common=666");
优先级: args> yaml> code
5. @validated 1.5.3 后 才有
@configrationproperties ( prefix ="common”)
yaml:
common:
host:
port:
list: // #{'${listParm}‘.split(’,‘)}
- aaa
- bbb
map:
key1:value1
key2: value2
mapParam: "{key1:'value1', key2:'value2'}"
6. lombok
@data @tostring(exclude="password")
7. RestController Controller 区别
8. logback configration.. application.yaml文件中
logging:
file:
level:
actuator 监控,动态调整日志级别 , 1.5 之后
9. springboot json converter 默认 jackson gson fastjson(不支持)
10. 父工程 使用dependencyManage 引入springboot springcloud, 实现双继承时,需要加<type>pom></type><scope>import</scope>
11. spring-cloud-config-server 配置:
spring.cloud.config.server.git.username
spring.cloud.config.server.git.password
spring.cloud.config.server.git.uri
spring.cloud.config.server.git.searchPaths:/{application}
spring.cloud.config.server.git.fore-pull:true
spring.cloud.config.server.git.basedir: /var/config // 默认为/tmp下, 此处需要修改 配置存放的目录
spring-cloud-config-client配置: bootstrap.yml
spring.cloud.config.uri: http://127.0.0.1:8888
spring.cloud.config.fail-fast: true
server.port:8881
12. spring session设置过期时间 启动类上增加如下注解
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 120, redisNamespace = "spring:session:taurus")
@Data
@configproperties(prefix="") //推荐使用
public class Cloudconfig{}
@EnableConfigurationProperties(CloudConfig.class) 放在controller上
@Resource
private CloudConfig cloudconfig;
优先级:
1》2》3
1.项目目录里面的配置 /application-name 项目独立的配置
2. 仓库根目录里面的配置 / 统一的配置
3. 代码本地的配置 开发环境经常需要修改的配置
如何 实现 动态更新:
1. acturator 引入
2. management.address
management.security.enable:false
3. Cloudconf配置类 @RefreshScope
4. controller类 @RefreshScope
@hystrixcommand 默认10个并发
commandproperties={@hystrixProperty(name="execution.isolation.strategy",value="Thread"}
服务限流策略: 线程池 信号量
commandproperties={@hystrixProperty(name="execution.isolation.strategy",value="Thread"}},
ThreadPoolProperty={@HystrixProperty(name="coreSize",value="13")}}
常用配置项:
---------------springcloud 2.0.0
server.port
server.tomcat.accept-count:1200
server.tomcat.max-connections:1000
max-threads:1000
min-spare-threads:100
spring.application.name
spring.datasource.hikari.mininum-idle:10
maximum-pool-size:15
type: com.zaxxer.hikari.HikariDataSource
redis.cluster.max-redirects:3
jackson.serilization.write-dates-as-timestamps: true
servlet.multipart.max-file-size: 1MB
max-request-size:10MB
feign.hystrix.enabled: true
mybatis.configuration.map-underscore-to-camel-case: true
ribbon.ReadTimeout: 30000
ConnectTimeout: 30000
spring.servlet.multipart.max-file-size: 30MB
spring.servlet.multipart.max-request-size: 30MB
---------------springboot 1.5.9
hystrix.threadpool.default.coreSize: 200
spring.zipkin.base-url: ..........:9411
sleuth.sampler.percentage: 1 生产环境改为0.1
kafka.consumer.auto-offset-reset: earliest
group-id
key-deserializer : org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
producer:
key-serializer : org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
eureka.client.registerWithEureka: true
fetchRegistry: true
serviceUrl.defaultZone
instance.prefer-ip-address: true
feign.hystrix.enabled: true
hystrix.threadpool.default.coreSize: 200
slf log 冲突:
build.gradle中增加:
configurations{
compileOnly {
extendsFrom annotationProcessor
}
all*.exclude module : 'spring-boot-starter-logging'
}
如果,您认为阅读这篇博客让您有些收获, 如果,您希望更容易地发现我的新博客,不妨关注一下。因为,我的写作热情也离不开您的肯定支持。
感谢您的阅读,如果您对我的博客所讲述的内容有兴趣,请继续关注我的后续博客。
因为有小孩,兼职卖书,路过的朋友有需要低价购买图书、点读笔、纸尿裤等资源的,可扫最上方二维码,质量有保证,价格很美丽,欢迎咨询! 欢迎关注微信公众号:18般武艺