Home > Java > javaTutorial > body text

What are the two methods of springboot hot deployment?

王林
Release: 2023-06-03 11:51:27
forward
739 people have browsed it

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>
Copy after login

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>
Copy after login

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

  1. Spring Boot is the integration of Spring and Spring MVC, while Spring MVC is just a module of Spring , a lightweight Web layer framework

  2. 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

  3. Difficulty, and Spring MVC needs to rely on xml configuration for development

  4. 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

  5. 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

  • ##Zookeeper guarantees CP,

  • Eureka guarantees AP

The difference between # and $ in mybatis

# is equivalent to adding double quotes to the data, and $ is equivalent to directly displaying the data

  • The data passed in will be treated as a string and enclosed in double quotes. For example: order by #user_id#, if the value passed in is 111, then the value when parsed into sql is order by "111". If the value passed in is id, the parsed sql is order by "id".

  • $ Display the incoming data directly and generate it in sql. For example: order by $user_id$, if the value passed in is 111, then the value when parsed into sql is order by user_id. If the value passed in is id, the parsed sql is order by id.

  • 3# Method can prevent sql injection to a great extent.

  • #$ method cannot prevent Sql injection. The

  • $ method is generally used to pass in database objects, such as table names.

  • Generally, don’t use $ if you can use #.

When using order by dynamic parameters when sorting MyBatis, you need to pay attention to using $ instead of


#string replacement


By default, using the syntax of the form #{} causes MyBatis to create a prepared statement property and set a safe value (such as ?) against it. This is safe, fast and preferred, sometimes you just want to insert an unchanged string directly into the SQL statement. For example, like ORDER BY, you can use it like this:

ORDER BY ${columnName}

MyBatis will not modify or escape the string here.

How Redis eliminates data

  1. volatile-lru: From the data set with expiration time set (server.db[i].expires) Select the least recently used data to eliminate

  2. volatile-ttl: Select the data that will expire from the data set (server.db[i].expires) with an expiration time set

  3. volatile-random: Randomly select data from the data set (server.db[i].expires) with an expiration time set for elimination

  4. allkeys-lru: Select the least recently used data from the data set (server.db[i].dict) to eliminate

  5. allkeys-random: Select the least recently used data from the data set (server.db[i] ].dict) randomly select data for elimination

  6. no-envivtion(eviction): prohibit eviction of data

LRU mechanism:

Redis saves the lru counter server.lrulock, which will be updated regularly (redis timer program severeCorn()). Each redis object will set the corresponding lru value. Each time the object is accessed Every time, redis will update redisObject.lru.


LRU elimination mechanism: randomly select several key-value pairs in the data set, and remove the key-value pair with the largest lru among them. Therefore, redis does not guarantee that the eliminated data are the least recently used, but are randomly selected key-value pairs.

TTL mechanism:

The key-value pair expiration schedule is saved in the redis data set structure, that is, redisDb.expires.


TTL elimination mechanism: Randomly select several key-value pairs in the data set, and remove the key-value pairs closest to the expiration time. Therefore, redis does not guarantee that the eliminated data is the closest to the expiration time, but the randomly selected key-value pairs.

When redis executes a command on each service client, it will detect whether the memory used is excessive

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template