In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to practice Spring Boot deeply, in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Spring Boot, which is easy to use, is undoubtedly a beacon for beginners of Java development, as well as a right-hand man for experienced Java developers. Rapid development is the original intention of R & D Spring Boot, which is not only the lifelong pursuit of a development team, but also a guarantee for an enterprise to liberate productivity and improve production efficiency.
Spring Boot's component integration rules perfectly integrate cloud application development tools, making it in a leading position in the field of cloud computing, providing a simpler and faster way to create highly available and high-performance services.
Spring Boot is developed from the Spring framework, so for a large group of users who use the Spring framework, with the widespread use of Spring Boot, many developers will become its fans.
1. Applicable scenarios for Spring Boot
1. What are the usage scenarios of Spring Boot when developing an enterprise project, and what are the known pitfalls?
SSO, distributed file systems, micro-service usage, and so on, are all very useful in enterprise applications. If you insist that there is a hole, it means that there are more services, and service deployment and operation and maintenance management must be to a higher level, otherwise it will appear chaotic.
two。 Personally, it is really efficient to build quickly, and this framework is the product of crystallization after a lot of practice. However, for newcomers, the direct application of Spring Boot still does not feel ideal, which may hinder the newcomers' understanding of the Spring framework. For Spring Boot itself, it is still very good, cloud deployment, rapid build are very good. My question is, does the company have any requirements for the application of Spring Boot? Under what circumstances does a general developer use it? Are there any requirements for enterprise-level development?
Spring Boot has no special requirements for background knowledge, so it is easier for newcomers to build a project to follow the development. For the company's requirements, it mainly depends on the scale of the project and the way it is deployed. If you use Docker deployment and need to set up load balancers, there will be higher requirements for operation and maintenance personnel and servers.
3. We often see Spring Boot associated with micro-services, because Spring Boot development and deployment is relatively fast, can you elaborate?
Spring Boot is indeed designed for rapid development, and its easy-to-use features do reduce the burden on developers, thus increasing development productivity. Your question requires a comprehensive understanding of Spring Boot, which can be understood through its official website.
Full reference DEMO-run an application without writing a single line of code
4. What kind of project is this framework suitable for development?
It is most suitable for developing Web application projects.
II. Spring Boot and jar
1. I have been using Spring Boot for several months, and I have begun to use Spring Boot to build the company's basic system. I understand that Spring Boot should advocate deployment in the form of jar, but it is too slow to deploy in this way when the size of the package is too large. Before, our business and servers were all in foreign countries, and the speed of upload was very slow. Is there any other way except to change it to war release?
In fact, the best way is to use jar, and then use Docker to publish. If the jar package for a project is too large, look at the main reason for this. Is it because there are too many resource files in the jar package, or whether the business contained in the project is too complex? if it is the former reason, consider optimizing some image resources, or using a distributed file system to store image resources. If it is the latter reason, do you consider subdividing the original project in a modular way?
@ DEMO http://git.oschina.net/icer/iblog contributed by the uncle of mushroom pickers. Build a shelf with SpringBoot and integrate freemarker and mybatis.
2. Spring Boot integrates the server and publishes as jar files, reducing dependence on external files and environment. But long-term integration leads to excessive size, which is indeed a problem, can you consider making some tools to lose weight on jar?
This requires an analysis of what causes the jar to be too large. If it is caused by too many resource files, optimize the design of some pictures, or use other ways to link the resource files. If it is caused by too much business and complexity in a project, consider whether the project can be split.
3. If Spring Boot is used to make jar service startup, how to measure the service granularity. Because each service has to run Spring, or will also add a dubbo dependency, and so on. Run multiple instances, which is repeated. In fact, it is the point of single application and distributed application.
It mainly depends on how you configure the service. If you use Spring Cloud's service discovery to manage services, you can support multiple services to provide services at the same time through the configuration of load balancer.
4. Spring Boot also supports the deployment of applications in standard war mode, but requires minor adjustments on the startup class, and does not emphasize deployment in jar mode all the time.
Spring Boot should encourage deployment in the form of jar, and along with Spring Boot should be to promote micro services. Personal opinions are for discussion only. (@ Uncle mushroom picker)
5. When using Spring Boot, the page file will be packaged into jar. If only the page file is updated, the jar will be packaged and uploaded. Is there an easy way? Similar to the original Tocmat deployment, you can modify the page file directly. That doesn't need to be rebooted?
Can be deployed using war.
6. How to separate libs jar from app jar in a Spring Boot project? most of the time, I just update the application layer code, compile and upload it locally, and start it through a script when starting, so how do I package and start libs and app respectively?
You can do what you want by publishing it in war.
III. Spring Boot and Docker
1. Please briefly introduce the combination of Spring Boot and Docker
To put it simply: package the Spring Boot project into jar and deploy it through Docker. Projects developed with Spring Boot are very suitable for deployment with Docker.
There is no relationship between the two things. The main purpose of Spring Boot is to simplify the use of configuration files in the development and deployment process, using a lot of established rules, according to these agreed rules to develop, you can greatly reduce the use of configuration files, or even not using configuration files at all. Docker is just a tool to package the runtime environment, such as OS, JVM, Nginx, and so on. Put the executable jar package generated by Spring Boot into this runtime environment to run. Both of these tools only simplify the complicated process of development and operation and use a lot of automated processing techniques. (@ clear without worry)
2. Does the best practice of Spring Boot from development to deployment rely on container technology, and how to make a smooth transition to Docker containers?
Spring Boot does not rely on the Docker container, but can also use war or the traditional way to directly use the file system to publish, but the use of Docker, can give play to its advantages in all aspects.
3. Can you share your experience with Spring Cloud and Docker deployment?
Publish a Spring Boot project (https://my.oschina.net/syic/blog/799656) using Docker
4. Migrate old projects to Spring Boot
1. What are the conditions for transferring the old project to Spring Boot?
Without any conditions, with Spring Boot, it is best to redesign the original project or have the original logic rebuilt.
two。 Is the micro-service architecture more suitable for Spring Boot? So for old systems or code, how do I go to Spring Boot?
All projects developed using Web are suitable to use and benefit from the Spring Boot framework, and micro-service development is a major feature of it. The code of the old system cannot be converted and can be rebuilt using the original business logic.
5. Comparison with related projects
1. A few years ago to do the development or use of Spring, including Spring's Bean factory program and SpringMVC, now the main business development of the general use of the company's self-research framework, so Spring feels relatively rusty, I want to know, Spring Boot compared with the Spring a few years ago, what aspects of development and changes, can you talk about it?
Spring Boot is built on the basis of Spring, retaining some of the essence of Spring, but also abandoning some dregs, as shown in:
Unified engineering configuration, can not use XML configuration
Use some components with automatic configuration
Embedded Tomcat, performance metrics and other services
It is more convenient to deploy independently or configure into a highly available and high-performance platform using Docker
2. What are the main differences between Spring Boot and traditional SSH frameworks?
Spring Boot can simplify configuration as much as possible, can also embed services such as Tcomcat, and is more handy in developing enterprise applications, distributed applications and so on. What is more commendable is that it is very easy to use, very suitable for rapid development, and in line with the goal of software engineering component development.
3. What's the difference between Spring Boot and Spring MVC?
Spring MVC still belongs to the Spring framework. Spring Boot is a brand-new development framework based on Spring.
4. What are the advantages of Spring Boot building microservices and some new ones such as light java framework and sparkjava in building microservices?
In the Spring Boot family, using the cloud application development tool set Spring Cloud to develop micro-service applications has a unique advantage. The micro-service here refers to the distributed application system with powerful function and single business, not simply refers to the micro-structure of the project.
5. Does it mean that you don't have to do Spring, SpringMVC, Hibernate, Struts, MyBatis and so on with Spring Boot?
Yes, exactly. For databases, you can catch them all with JPA.
6. Spring Boot still likes it and simplifies a lot of configuration, but in practice, the division of micro services is a problem.
The division of services has nothing to do with Spring Boot. One of the difficulties of micro-services is the division of services, some services are divided according to technical characteristics, such as push services, sms services and so on. Some are divided according to the characteristics of the business, such as order services, and some are tiered according to the actual situation.
7. With Spring Boot, do other necessary frameworks need to be configured?
If you use Maven or other project management tools, you can reference dependency packages in the project configuration.
VI. Problems encountered in use
1. Spring Boot has a variety of Web containers, such as default Tomcat, Undertow, etc., which is better to use comprehensively. How does Undertow configure http to automatically jump to https like Tomcat?
Jetty looks smaller than Tomcat, but overall, it's more realistic to use the default Tomcat.
The performance of Undertow is much better than that of Tomcat, and https generally does not need to be matched at the Undertow layer. It is common to add a Nginx before Undertow and configure it in Nginx. (@ clear without worry)
The performance test Undertow is slightly better than Tomcat. Safe can use Tomcat, want to change the way of thinking can use Undertow. The compromise between http redirect to https and Undertow is to introduce Spring Security. However, generally speaking, the front end should be equipped with Nginx or Apache Http Server to open the https service to the outside world, and the internal http should be used as the reverse proxy channel protocol. (@ 2 is basically qualified)
Http://menelic.com/2016/01/06/java-rest-api-benchmark-tomcat-vs-jetty-vs-grizzly-vs-undertow/ read this blog, although the Tomcat is slower, but in the actual business Tomcat will not be a bottleneck, the use of Tomcat is also a good choice, after all, so many years of use, is also familiar with the configuration. (@ dream day and night)
two。
I've been using Spring Boot for a long time, starting with 1.2.5. recently, a project is expected to use distributed high availability, and I've got all the frameworks I need to work out, but in the end, customers cancel distributed high availability and adopt the traditional model. Java is only responsible for the backend interface, and APP accepts data. I now have a permission problem. The permissions originally used by Spring Security are separated from the front and back ends, but now there is only the interface. How to manage this permission? I think there is an answer in it that Spring Cloud is used for permission control. Is this Cloud onerous to the traditional mode?
Scheduled task scheduling, whether the own Quartz scheduling supports clustering, multiple nodes (non-cluster ng distribution), but scheduled tasks I want him to cluster, multiple nodes are not allowed to start scheduling tasks, only one node cannot execute other nodes can trigger, does this need to be monitored by tools such as zookeeper?
For enterprise applications, rights management is recommended to use SSO, which is actually used in the book "in-depth practice of Spring Boot", mainly using the technologies of Spring Security and OAuth3.
Like Spring-Cloud-Eureka, Zookeeper is a management tool for service registration and discovery, while Spring-Cloud-Eureka is used in Spring Boot and is more suitable for scheduling micro-services developed using Spring Cloud. As for what you said about scheduled task scheduling, it should not fall within this scope.
Toss authority will have a csrf problem, the building is mainly ready to share some experience. Problem: if csrf is enabled, a csrf string will be generated when rendering the page template. If the post submission can be taken with it, but if it is written out to be the interface of json, the csrf will not be fetched, so a csrf-related error will be reported when submitting the post request. (@ Pengya)
3. How can Spring Boot better and more succinctly implement multi-table association queries?
Establish the association relationship for multiple tables during entity modeling, so that when querying an entity object, you can find out the other objects associated with it, that is, to realize multi-table association query.
4.
Do microservices built using Spring Boot take into account the permissions between services, such as access rights? if necessary, does Spring Boot itself provide a better solution?
Does Spring Boot currently have good support and customization for Spring Cloud ecology?
Spring Boot and its predecessor, Spring, can provide good support for any third party, let alone Spring Cloud. For the security management and access control of the system, it is recommended to use Spring Cloud's SSO, which can achieve very harmonious results with the Spring Boot framework.
5. When using Spring Boot to develop the company's products, it is split according to the business, so that N jar will appear when the final deployment. In this case, is there any other way than to deploy with Docker? Is there anything you need to pay attention to in terms of deployment?
N seems to be a little big, the original project is divided into more than a dozen projects, it is already very good. The advantage of using Spring Boot is that you can unify the project configuration, use discovery services, better manage load balancing and improve the high availability of the system.
6. I would like to use the way of jar release, how to restart the system automatically after the start?
Spring Boot packages a runnable jar, which is started using the Java command. Just write a shell script to start it, and set the shell script to boot. No matter which way you deploy, automatic startup needs to be scripted. (@ clear without worry)
7. In Spring Boot, how to set the maxConnections property of Tomcat through parameter configuration?
There doesn't seem to be this configuration parameter in the Spring Boot configuration file, but if you must, you can also publish the project as war and configure it as you did with Tomcat before.
8. How about Spring Boot doing REST API development? If the parameter model accepted by Controller is complex, basically object layer by layer, how to customize this kind of API interface?
Using the annotation @ RepositoryRestResource in the repository interface, you can provide Rest API directly
Use @ RestController in the controller, where the defined URL is also a Rest resource
9. Does Spring Boot have a hot deployment during the development phase? Like JRebel.
If it is set to connect to the Tomcat server to start the application, it can be set to hot deployment.
This is the answer to the question about how to practice Spring Boot in depth. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.