Spring/spring boot/spring cloud Development Summary, springcloud
Background
Dubbo and dubbox are used for remote RPC calls. As the community suspends maintenance and responds to future development, we are ready to try new technologies (maybe not a new technology at this time) and choose to use the spring cloud architecture. During this period, the spring boot project was used for development and the results were good. So I want to refactor the original spring Project to spring cloud step by step, so there will be various problems in development.
Problem
The problem is always revealed step by step along with the development, and always solves the problem:
Spring cloud problems:
1. Cross-System Call, unable to receive parameter passing objects
Solution: the service provider can @ RequestBody (ps: public void saveUser (@ RequestBody User) before the object parameters. The data is in the report style.
2. The retry problem between systems may result in repeated calls of normal business data, resulting in junk data.
The solution is divided into two steps and all are configured by the caller. The first step is to add a class:
In return, refer to feign. Retryer. The method name is arbitrary.
@Configurationpublic class FeignConfig { @Bean public Retryer feignRetryer() { return new Retryer.Default(100, SECONDS.toMillis(1), 0); }}
Step 2:
# Max number of next servers to retry (excluding the first server)
Sample-client.ribbon.MaxAutoRetriesNextServer = 1 for cluster services will randomly select the next service, it is possible to choose to access your own. If the cluster is not set to 1, it will access itself and cause two accesses.
Sample-client can be deleted from multiple servers.
View the configuration. For the configuration section, click here:
# Max number of retries on the same server (excluding the first try)
Sample-client.ribbon.MaxAutoRetries = 1 found useless
3. Deploy the server. Services in the Registration Center exist, but data cannot be accessed. The service is rejected.
Solution: in fact, this is a note. Generally, SpringApplication is used to start the project. The tomcat port and server. port (spring boot) configuration are inconsistent during service packaging and deployment. It is suggested that spring cloud accesses to obtain the host and port from the registration center, and access the service based on the host and port, but the port set by the Service tomcat is inconsistent with the configuration, resulting in problems.
Spring boot problems:
1. The project can be started normally using SpringApplication, but the page cannot be accessed
Solution: @ ComponentScan only scans the statement in the package structure (including the sub-package) of the current program
|-Src
|-Main
|-Java
|-Com
|-Controller/service/dao
|-SpringApplication. java
2. Question about the request url response. Different suffixes have different responses.
Solution: this scenario is because spring boot has multiple view Resolvers, and ajax requests can directly use a/B, page a/B .htm
Spring problems:
1. spring calls to the spring cloud Project
Solution: Use HttpClient to set the request header Content-Type: application/json to access spring cloud's external system (gateway ).
Exception:
Spring cloud has Hystrix Route Breaks. Although there are many advantages, each interface must be disconnected accordingly. If there is a difference in the processing logic, I will not talk about the difference. Because we return results in a unified manner, we can use global exception interception to record log return failures. This disadvantage is that the access exception can be handled. If there is no access timeout, the access will be captured.
Discussion
I hope you can give me some advice if you are not proficient in learning. Some of them are confused. When spring accesses spring cloud, it is finally packaged into a war package for deployment and release. I personally think spring can also be registered in the Registration Center. If you want to know it, share it with me.