The difference between springboot and springmvc
spring boot has embedded tomcat, Jetty and Undertow containers, which can be run directly without any further deployment;
spring boot automatically Configuration, reducing a large number of configurations of xml files; reducing the complexity of project construction
Spring MVC is an MVC framework based on Servlet. It mainly solves the problems of WEB development, because the configuration of Spring is very complex, various XML, JavaConfig and hin are relatively cumbersome to handle. Therefore, in order to simplify the use of developers, Spring boot was creatively launched. Convention is better than configuration, which simplifies the spring configuration process.
Spring is an "engine";
Spring MVC is an MVC framework based on Spring;
Spring Boot is a set of rapid development integration packages based on Spring4's conditional registration .
Two ways of springboot hot deployment
SpringBoot devtools hot deployment is only available after SpringBoot 1.3
①: spring-boot-devtools ②: Spring Loaded
Method 1:
Add dependencies in the project's pom file:
<!--热部署jar--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
Then: use shift ctrl alt "/" (shortcut key in IDEA) to select " Registry" and then check compiler.automake.allow.when.app.running
Method 2:
Add the following code to the project
<build> <plugins> <plugin> <!-- springBoot编译插件--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <!-- spring热部署 --> <!-- 该依赖在此处下载不下来,可以放置在build标签外部下载完成后再粘贴进plugin中 --> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.6.RELEASE</version> </dependency> </dependencies> </plugin> </plugins> </build>
You need to use mvn after adding it Instruction operation:
First find the Edit configurations in IDEA, and then perform the following operations: (Click the " " in the upper left corner, then select maven, the right panel will appear, enter the command as shown in the red underlined area , you can name the command (named here as MvnSpringBootRun))
Click to save and it will appear in the IDEA project running section. Click the green arrow to run
springboot configuration file
spring boot uses a global configuration file: mainly the following two types
application.properties: Example: server.port=9998
application.yml(YAML): Example: server:
port:8080
The function of the configuration file is mainly to modify the underlying default configuration of spring boot
Core annotations of Spring Boot
The annotation on the startup class is @SpringBootApplication, which is also the core annotation of Spring Boot. The main combination includes the following 3 annotations:
@SpringBootConfiguration: Combines the @Configuration annotation to implement the function of the configuration file.
@EnableAutoConfiguration: Turn on the automatic configuration function, you can also turn off a certain automatic configuration option, such as turning off the data source automatic configuration function: @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }).
@ComponentScan: Spring component scan.
The execution principle of spring boot's starter
Using the starter to realize automated configuration only requires two conditions-maven dependencies and configuration files. Here is a brief introduction starter implements the process of automated configuration.
Introducing maven is essentially importing the jar package. When spring-boot starts, it will find the resources/META-INF/spring.factories file in the starter jar package. According to the configuration in the spring.factories file, it will find the ones that need to be automatically configured. Class
The difference between Spring Boot and Spring MVC
Spring Boot is the integration of Spring and Spring MVC, while Spring MVC is just a module of Spring , a lightweight Web layer framework
Spring Boot can achieve almost zero configuration, all functions are developed using annotations, and the idea of 'convention over configuration' is used to simplify project development
Difficulty, and Spring MVC needs to rely on xml configuration for development
Spring Boot comes with built-in tomcat, so that after packaging into a jar package You can run it directly, or you can choose to use external tomcat
Spring Boot also inherits many third-party library configurations, such as JDBC, Mongo, Redis, etc. Applying these third-party libraries, almost Zero configuration is possible
What is the principle of service registration and discovery of springcloud
Eureka contains two components: Eureka Server and Eureka Client
Eureka Server provides service registration service
After each node is started, it will be registered in EurekaServer, so that the service registry in EurekaServer will store the information of all available service nodes. Information, service node information can be seen intuitively in the interface
EurekaClient is a Java client used to simplify the interaction of Eureka Server. The client also has a built-in, using polling (round- Robin) load balancer load algorithm. After the application starts, a heartbeat will be sent to Eureka Server (default period is 30 seconds). If Eureka Server does not receive the heartbeat of a node within multiple heartbeat cycles, EurekaServer will remove the service node from the service registry (90 seconds by default)
Eureka's three major roles :
Eureka Server provides service registration and discovery
Service Provider The service provider registers its own service with Eureka, so that the service consumer can Find
Service ConsumerThe service consumer obtains the registered service list from Eureka so that it can consume the service
As a service registration center, the advantages of Eureka and Zookeeper are:
The famous CAP theory points out that a distributed system cannot simultaneously satisfy C (consistency), A (Availability) and P (Partition Tolerance). Since partition fault tolerance P must be guaranteed in a distributed system, we can only make a trade-off between A and C.
So
The difference between # and $ in mybatis
# is equivalent to adding double quotes to the data, and $ is equivalent to directly displaying the dataORDER BY ${columnName}
How Redis eliminates data
LRU mechanism:
TTL mechanism:
The key-value pair expiration schedule is saved in the redis data set structure, that is, redisDb.expires.The above is the detailed content of What are the two methods of springboot hot deployment?. For more information, please follow other related articles on the PHP Chinese website!