Top 10 Commonly used frameworks:
One, for SpringMVC
Second, the Spring
Third, Mybatis
Fourth, the Dubbo
Five, the Maven
Sixth, the RabbitMQ
Seven, Log4j
Eight, Ehcache
Nine, Redis
Ten, Shiro
One, for SpringMVC
Spring Web MVC is a lightweight Web framework based on Java that implements the request-driven type of Web MVC design pattern, which uses the idea of MVC architecture pattern to decouple the responsibilities of the Web layer. Request-driven refers to the use of request-response model. The purpose of the framework is to help simplify development. Spring Web MVC is also meant to simplify our daily Web development.
Models encapsulate the application’s data and the GENERAL POJOs that they compose.
A View is responsible for rendering model data and generally the HTML output it generates, which can be interpreted by the client’s browser.
The Controller is responsible for processing the user’s request, creating the appropriate model, and passing it to the view rendering.
Spring’s Web Model – View –
The Controller (MVC) framework is designed around a DispatcherServlet that handles all HTTP requests and responses.
Spring Web MVC handles the flow of requests
The detailed steps are as follows:
1, first of all, the user sends a request ————> front-end controller, front-end controller according to the request information (such as URL) to decide which page controller to process and entrust the request to it, that is, the control logic part of the previous controller; Steps 1 and 2 in Figure 2-1;
2. After receiving the request, the page controller performs functional processing. First, it needs to collect and bind the request parameters to an object, which is called command object in Spring Web MVC, and verify it, and then delegate the command object to the business object for processing; Return a ModelAndView (model data and logical view name) after processing; Steps 3, 4, and 5 in Figure 2-1;
3. The front-end controller takes back control, and then selects the corresponding view for rendering according to the returned logical view name, and passes in model data for view rendering; Steps 6 and 7 in Figure 2-1;
4. The front-end controller takes back control again and sends the response back to the user, as shown in Step 8 in Figure 2-1. That’s the end of it.
Second, the Spring
2.1 IOC Container:
The IOC container is a container with dependency injection. The IOC container is responsible for instantiating, locating, configuring, and establishing dependencies between objects in an application. Applications do not need to directly new related objects in code; applications are assembled by the IOC container. In Spring, the BeanFactory is the de facto representative of the IOC container.
2.2, AOP:
To put it simply, it is to encapsulate the logic or responsibilities that have nothing to do with the business but are called by the business modules in common, so as to reduce the repetitive code of the system, reduce the degree of coupling between modules, and facilitate the future operability and maintainability. AOP represents a horizontal relationship
AOP is used to encapsulate crosscutting concerns, which can be used in the following scenarios:
The Authentication authority
Caching cache
Context passing
Error handling Error handling
Lazy loading
Was Debugging Debugging
Logging, tracing, Profiling and Monitoring record tracking optimized calibration
Performance optimization
Persistence Persistence
Resource pooling Resource pools
Synchronization synchronous
The Transactions transaction
Third, Mybatis
MyBatis is an excellent persistence layer framework that supports ordinary SQL queries, stored procedures, and advanced mapping. MyBatis eliminates almost all manual setting of JDBC code and parameters and retrieval of result sets. MyBatis uses simple XML or annotations for configuration and raw mapping to map interfaces and Java’s POJOs (Plain Old Java Objects) to records in the database.
Overall process:
(1) Load and initialize the configuration
Trigger condition: The configuration file is loaded
Load the SQL configuration information into a MappedStatement object (including the incoming parameter mapping configuration, executed SQL statements, and result mapping configuration) and store it in memory.
(2) Receive the call request
Trigger condition: call the API provided by Mybatis
Incoming parameter: the ID of the SQL and the incoming parameter object
Processing: The request is passed to the lower request processing layer for processing.
(3) Processing operation requests
Trigger condition: the API interface layer passes the request
Incoming parameter: the ID of the SQL and the incoming parameter object
Processing process:
(A) Find the MappedStatement object based on the ID of the SQL statement.
(B) Parse the MappedStatement object based on the passed parameter object to get the SQL to be executed and execute the passed parameter. © get database connection, execute to database according to the final SQL statement and execute the incoming parameters, and get the execution result.
(D) According to the result mapping configuration in the MappedStatement object, the obtained execution result is transformed and the final processing result is obtained.
(E) Release connection resources.
(4) Return processing results Return the final processing results
One of the most powerful features of MyBatis is its dynamic statement capability. If you’ve ever worked with JDBC or similar frameworks, you know how painful it can be to join SQL statements together conditionally, making sure you don’t forget Spaces or omit a comma after columns, etc. Dynamic statements take care of all this pain.
Fourth, the Dubbo
Dubbo is a distributed services framework dedicated to providing high-performance and transparent RPC (Remote Procedure Call Protocol) remote service invocation solutions, as well as SOA service governance solutions. To put it simply, Dubbo is a service framework. If there is no distributed requirement, there is no need to use a distributed service framework like Dubbo, and it is essentially a service invocation east east. In other words, it is a distributed framework for remote service invocation.
1. Transparent remote method invocation, which calls remote methods just like local methods, with simple configuration and no API intrusion.
2. Soft load balancer and fault tolerance mechanism can replace hardware load balancer such as F5 on the Intranet to reduce cost and single point.
3, automatic service registration and discovery, no longer need to write the service provider address, registry based on the interface name query service provider IP address, and can smoothly add or delete service providers.
Node roles:
Provider: exposes the service Provider of the service.
Consumer: Service Consumer that invokes the remote service.
Registry: A Registry where services are registered and discovered.
Monitor: monitors The Times and time of service invocation.
Container: service running Container.
Five, the Maven
Maven is a project management and build automation tool that more and more developers are using to manage JAR packages in their projects. But for us programmers, we care most about its project-building capabilities.
Sixth, the RabbitMQ
Message queue usually extracts some time-consuming operations that do not need to be returned immediately from the project and conducts asynchronous processing, which greatly saves the server’s request response time and improves the throughput of the system. RabbitMQ is a highly concurrent and reliable AMQP message queue server implemented in Erlang. Erlang is a dynamically typed functional programming language. In Erlang, each Actor corresponds to an Erlang process that communicates with each other through messaging. The immediate benefit of communicating between processes through messaging over shared memory is the elimination of direct locking overhead (regardless of the locking application in the underlying implementation of the Erlang virtual machine).
The Advanced Message Queue Protocol (AMQP) defines a Message system specification. This specification describes how subsystems interact through messages in a distributed system.
Seven, Log4j
The priority of logging can be OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL, or whatever level you define.
Eight, Ehcache
EhCache is a pure Java in-process caching framework. It is fast and clean, and is the default CacheProvider in Hibernate. Ehcache is a widely used open source Java distributed cache. Targeted at general-purpose caches,Java EE and lightweight containers. It features memory and disk storage, cache loaders, cache extensions, cache exception handlers, a GZIP cache servlet filter, support for REST and SOAP apis, and more.
Advantages:
1, fast
2, simple
3. Multiple caching strategies
4. There are two levels of cached data: memory and disk, so there is no need to worry about capacity
5. Cached data will be written to disks during vm restart
6. Distributed caching can be carried out through RMI, pluggable API, etc
7. Listener interface with cache and cache manager
Support for multiple cache manager instances, as well as multiple cache areas of an instance
9. Provide Hibernate cache implementation
Disadvantages:
1. DiskCache takes up a lot of disk space. This is because DiskCache has a simple algorithm, which also leads to high Cache efficiency. It simply appends storage to elements directly. So searching for elements is very fast. If DiskCache is used, the disk will fill up quickly in very frequent applications.
2. Data security cannot be guaranteed: when a Java file is killed suddenly, a collision may occur. The EhCache solution is to rebuild the cache if the file conflicts. This can be detrimental when Cache data needs to be saved. Of course, caching simply speeds up, but does not guarantee data security. If you want to ensure the security of data storage, you can use Bekeley DB Java Edition. This is an embedded database. This ensures storage security and space utilization.
Nine, Redis
Redis is a key-value storage system. Like Memcached, it supports storing a relatively large number of value types, including String (string), list(linked list), set(collection), zset(sorted set – ordered collection), and hash (hash). All of these data types support push/ POP, add/remove, intersection union and difference sets, and richer operations, all of which are atomic. On this basis, Redis supports sorting in various ways. As with memcached, the data is cached in memory for efficiency. The difference is that Redis periodically writes the updated data to disk or the modified operation to the appended record file, and on this basis realizes master-slave synchronization. Redis databases are entirely in memory, using disks for persistence only. Redis has a richer set of data types than many key-value data stores. Redis can copy data to any number of slave servers.
1.2 Advantages of Redis:
(1) Extremely fast: The speed of Redis is very fast, which can execute about 110,000 sets per second and about 81,000 + records per second.
(2) Support rich data types: Redis supports most of the data types that most developers already know like list, set, ordered set, and hash. This makes it very easy to solve all kinds of problems because we know which problems can be dealt with by the number of it
(3) All operations are atomic: All Redis operations are atomic, which guarantees that if two clients access the Redis server at the same time, they will get the updated value.
(4) Multi-functional utility: Redis is a multi-functional tool that can be used in multiple applications such as caching, messages, queues (Redis native support publish/subscribe), any ephemeral data, applications such as Web application sessions, Web page hit counts, etc.
1.3 Disadvantages of Redis:
(1) Single thread
(2) Memory consumption
Ten, Shiro
Apache Shiro is a security framework for Java designed to simplify authentication and authorization. Shiro is available in both JavaSE and JavaEE projects. It is mainly used for authentication, authorization, enterprise session management and encryption. Shiro’s features are as follows:
(1) Identity authentication/login to verify whether the user has the corresponding identity;
(2) Authorization, namely, authorization verification, verifies whether an authenticated user has a certain permission; Check whether a user can do something, for example, check whether a user has a role. Or fine-grained verification whether a user has a certain permission on a resource.
(3) Session management, that is, after the user logs in, it is a session, and all its information is in the session before exiting; The session can be in a normal JavaSE environment or in a Web environment;
(4) encryption, to protect the security of data, such as password encryption stored in the database, rather than plaintext storage;
(5) Web support, can be very easy to integrate into the Web environment; Caching: For example, after a user logs in, the user information and role/permission do not need to be queried every time. This improves efficiency.
(6) Shiro supports concurrent verification of multi-threaded applications, that is, if you start another thread in one thread, the permission can be automatically propagated to the past;
(7) Provide test support;
(8) allow one user to pretend to be another user (if they allow it) for access;
(9) Remember me, this is a very common feature, that is, once you log in, the next time you do not need to log in. The written description may not be enough to make apes fully understand the meaning of specific functions. Let’s take login authentication as an example to introduce Shiro to ape friends. As for the other functions, it is not too late for ape friends to explore their usage when they use them.
11. Design mode
This is not a framework and can be ignored, but the blogger thinks the idea of design patterns is important to understand. Thought:
Open and close principle:
The open closed principle means open for extensions, closed for modifications. When the program needs to be expanded, the original code should not be modified. Programming for interfaces, programming for interfaces, depends on abstractions rather than concrete. Try to use composition/aggregation rather than inheritance.
One entity should interact with other entities as little as possible, so that the functional modules of the system are relatively independent. Using multiple isolated interfaces is better than using a single interface.
Richter’s substitution principle:
(1) The ability of the subclass must be greater than or equal to the parent class, that is, the method that the parent class can use, the subclass can use.
(2) The same is true for the return value. Suppose a superclass method returns a List and a subclass returns an ArrayList, which is fine. If a superclass method returns an ArrayList and a subclass returns a List, it doesn’t make sense. Here the subclass has less ability to return a value than the parent class.
(3) There are exceptions thrown. Any subclass method can declare a subclass that throws an exception declared by the parent method. You cannot declare an exception that is not declared by the parent class.