Saturday, July 11, 2020

spring boot note


spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito
'Hamcrest' is an anagram of 'matchers' allowing match rules to be defined declaratively.These matchers have uses in unit testing frameworks such as JUnit and jMock. Hamcrest has been included in JUnit 4 since 2012, but was omitted from Junit 5 in 2017.

虽然,Spring Boot中实现了默认的error映射,但是在实际应用中,错误页面对用户来说并不够友好,我们通常需要去实现我们自己的异常提示。
创建全局异常处理类:通过使用@ControllerAdvice定义统一的异常处理类,而不是在每个Controller中逐个定义。@ExceptionHandler用来定义函数针对的异常类型,最后将Exception对象和请求URL映射到error.html


Spring Boot 2.2.6.RELEASE原理剖析

https://blog.csdn.net/zhaodongchao1992/article/details/105215849

https://blog.csdn.net/weixin_43570367/article/details/104960677

By default, all sensitive endpoints added by actuator are secured. This includes ‘/refresh' endpoint. For simplicity, we will turn off security by updating bootstrap.properties:
management.security.enabled=falseAdditionally, starting with Spring Boot 2, actuator endpoints are not exposed by default. To make them available for access, we need to add this in an application.yml:management:
endpoints:
web:
exposure:
include: "*"
Let's start the client first and update user role from existing ‘Developer' to ‘Programmer' in the properties file on GitHub. Config server will show updated values straight away; however, the client won't. To make client see new files we just need to send an empty POST request to ‘/refresh' endpoint, which was added by actuator:
$> curl -X POST http://localhost:8080/actuator/refreshWe will get JSON file back showing updated properties:[
  "user.role"
]The user role was updated successfully and by calling ‘/refresh' endpoint. Client updated configuration without restarting.
By using Actuator, we can refresh clients. However, in the cloud environment, we would need to go to every single client and reload configuration by accessing actuator endpoint.To solve this problem, we can use Spring Cloud Bus.
By using Actuator, we can refresh clients. However, in the cloud environment, we would need to go to every single client and reload configuration by accessing actuator endpoint.
To solve this problem, we can use Spring Cloud Bus.
Now, the client will have another endpoint ‘/bus-refresh'. Calling this endpoint will cause:
  • get the latest configuration from the config server and update its configuration annotated by @RefreshScope
  • send a message to AMQP exchange informing about refresh event
  • all subscribed nodes will update their configuration as well
This way, we don't need to go to individual nodes and trigger configuration update.
We will use spring-cloud-config-monitor to monitor configuration changes and broadcast events using RabbitMQ as transport.

Customizing the Management Endpoint Paths

You can use the management.endpoints.web.base-path property to change the prefix for your management endpoint, as shown in the following example:
management.endpoints.web.base-path=/manage
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver spring.datasource.type=oracle.jdbc.pool.OracleDataSource

System.out.println(jdbcTemplate.getDataSource().getConnection());
will print oracle.jdbc.driver.T4CConnection instead of HikariProxyConnection

No comments:

Post a Comment