Spring Boot installation and use (2021.10.28)

Spring Boot installation and use 2021.10.28

1. Introduction to Spring Boot

        Spring makes Java programming easyfastersimplersafer. SpringIt has become the most popular Javaframework in the world due to the great focus on speed, simplicity and productivity of project construction .

1.1 Why choose Spring?

        The Why Spring? Spring framework can be accompanied by a large number of tool libraries, which can save developers from writing a lot of extra code, thereby saving development time and energy and effectively improving development efficiency.

  1. Spring is everywhere : Whether it's streaming TV, online shopping, or countless other innovative solutions, developers around the world trust and use Spring libraries to deliver delightful experiences to millions of end users every day. experience. Of course, many of them come from alltechnology giantContributions from Alibaba , Amazon , Google , Microsoft, etc.
  2. Spring is flexible (more flexible) : Developers can use Springa flexible and comprehensive set of extensions and third-party libraries to build almost any application imaginable. Whether developers are webbuilding secure, reactive, cloud-based microservices for the enterprise or complex streaming data flows for the enterprise, it Springcan help.
  3. Spring is productive : SpringBootCombines webessentials like application context and an auto-configured embedded server to make microservices development a breeze. Thanks to SpringBootchanging the way of handling Java programming tasks, developers can combine Spring Bootwith Spring Cloudrich supporting libraries, servers, patterns and templates to safely deploy the entire microservices-based architecture to the cloud in as little time as possible.
  4. Spring is fast : SpringProjects are increasingly supporting a reactive (non-blocking) programming model for greater efficiency and better performance, enabling fast startup , fast shutdown , and optimized execution by default . SpringBootIt can help developers build applications easily and effortlessly, and even use Spring initializers to start a new Springproject in seconds.
  5. Spring is secure : SpringCommitters work with security professionals to patch and test any reported vulnerabilities, while third-party dependencies are closely monitored and updates are released regularly to ensure data and application security . In addition, Spring Securityit makes it easier for developers to integrate with industry-standard security solutions, and provides safe and reliable solutions by default.
  6. Spring is supportive (supported more) : As a large, global, and diverse community, Springthe community covers developers of all ages and abilities, from complete beginners to seasoned professionals. Wherever a developer is, he can find the support and resources he needs.

1.2 Functions of Spring

        SpringThe following functions can be realized:
        (1) Microservice (Microservices), the microservice architecture has gradually become a new normal. Building small, self-contained, ready-to-run applications brings great flexibility and extra resilience to your code. SpringBootMany purpose-built features in make it easy for users to build and run your microservices in production at scale.
        (2) Sensitive response system (Reactive), reactive systems have certain properties that make them ideal for low-latency, high-throughput workloads. Project ReactorWorks in tandem with Springthe product portfolio to enable developers to build responsive, resilient message-driven, enterprise-grade reactive systems.
        (3) Cloud operation (Cloud), developing distributed systems can be challenging. Complexity moves from the application layer to the network layer, requiring greater interaction between services. Code " cloud native " means dealing with the 12-factor concerns of external configuration, statelessness, logging and connecting to supporting services, and the SpringCloudproject suite contains many of the services needed to make an application run in the cloud.
        (4) Convenient network application (Web Applications), by removing most of webthe development-related boilerplate code and configuration, it Springimplements a modern webprogramming model that simplifies the development of server-side HTMLapplications, REST APIand bi-directional, event-based systems, making building webapplications fast and convenient.
        (5) Serverless (Serverless), serverless applications take advantage of modern cloud computing features and abstractions, allowing developers to focus on logic rather than infrastructure. In a serverless development environment, developers only need to focus on writing application code, while the underlying platform takes care of scaling, runtime, resource allocation, security, and other " server " specifications.
        (6) Event-driven (Event Driven), event-driven systems reflect how modern businesses actually work ( thousands of small changes happen every day ). Spring's ability to handle events and enable developers to build applications around events means that applications will stay in sync with the business. Spring has many event-driven options to choose from, from integration and streaming all the way to cloud functions and dataflows.
        (7) Batch processing (Batch), batch processing is able to efficiently process large amounts of data, which makes it well suited for many use cases. SpringBatchThe implemented industry standard processing patterns allow you JVMto build robust batch jobs on top of it. Mission-critical batch applications can be built by Springadding and other components from the portfolio .Spring Boot

1.3 Dependency package management tools for Spring projects (Maven or Gradle)

        The comparison between Maven and Gradle , their differences are mainly reflected in four aspects: flexibility , performance , user experience and dependency management .

  1. Flexibility: 以用户为中心,Gradle更加偏重底层基础,可扩展性强,易于建模,不仅允许使用C/C++进行本机开发,还可以扩展到任何生态系统.
  2. Performance: 就提高构建时间并加快发布速度而言,Gradle和Maven都采用某种形式的并行项目构建和并行依赖解析。最大的区别在于Gradle的工作回避机制和递增机制。Gradle和Maven用户都可以利用Gradle Enterprise中可用的构建缓存技术。Gradle用户通常会额外减少约50%的构建时间,而Maven用户通常会减少约90%.
    insert image description here
  3. User Experience: 历史深远的Maven通过IDE提供的支持对许多用户来说更好。然而,Gradle的IDE支持继续快速改进。Gradle提供了一个交互式的基于web的UI,用于调试和优化构建:[Build Scan](https://gradle.com/build-scans?_ga=2.40948836.711658238.1635427287-13996288.1635427287). 这些也可以在本地托管,以允许组织收集构建历史并进行趋势分析、比较构建以进行调试或优化构建时间.
  4. Dependency management: 作为库使用者,Maven允许覆盖依赖项,但只能按版本覆盖。Gradle提供了可定制的依赖项选择和替换规则,这些规则可以声明一次并处理项目范围内不需要的依赖项。这种替代机制使Gradle能够一起构建多个源项目以创建复合构建。Maven几乎没有内置的依赖范围,Gradle允许自定义依赖范围,从而提供更好的建模和更快的构建。作为库生产者,Gradle允许生产者声明'api'和'implementation'依赖项,以防止不需要的库泄漏到使用者的类路径中。Maven允许发布者通过可选的依赖项提供元数据,但仅作为文档。Gradle完全支持功能变体和可选依赖项.

2. Spring Boot installation prerequisite environment (Java must + Maven / Gradle)

2.1 Install Java

insert image description here

insert image description here
        Go to the Java download page on Oracle’s official website to download the Java version you need. The Java 8 version is used here jdk-8u221-windows-x64.exe. Double-click to run and select the installation directory you want. Because the JDKinstallation package will install the corresponding version JDKand at the same time JRE, the installation is successful here. The resulting directory is shown in the figure below.

insert image description here
insert image description here
        Then set the environment variable for Java, first create a new system environment variable JAVA_HOME, set its value D:\Program Files (x86)\Java\jdk1.8.0_221(that is, the JDK installation directory); then create a new system environment variable classpath, set its value .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;, and then add it to the value of the system environment variable Path %JAVA_HOME%\bin;. Finally Win+ Ropen the cmd command line window, enterjava -versionjavaAfter pressing Enter, if the corresponding version appears , the environment configuration is successful.
insert image description here

2.2 Maven configuration

insert image description here

        Before you are ready to install Maven, you need to install it JDK 1.7+. Go to the Maven official website to download the latest version Maven 3.8.3, or download the historical version from the Maven Archive library according to your own needs Maven. Here, you can download apache-maven-3.8.3-bin.zipthe compressed package free of installation files and unzip it to the D drive .
insert image description here
insert image description here
insert image description here
insert image description here

        Then create a new system environment variable MAVEN_HOME, set its value D:\program files\apache-maven-3.8.3, and add its subdirectory binfolder to the system environment variable Path. In addition, note that you should also create a new system environment variable M2_HOME, and set its value to D:\program files\apache-maven-3.8.3(In order for the Spring Boot project to be able to find the needs of the Maven directory)。
insert image description here
insert image description here

insert image description here
        Win+ ROpen the cmd command line window, enter mvn --version, if the Maven version prompt appears, the Maven configuration is successful.
insert image description here
insert image description here
        Then, after creating a new folder Mavenin the installation directory , open the files in the folder , and add the local warehouse location in the corresponding position in the figure below ;repositoryconfsettings.xmlD:\program files\apache-maven-3.8.3\repository

<localRepository>D:\program files\apache-maven-3.8.3\repository</localRepository>

insert image description here
        At the same time, maventhe modified download address is the Alibaba Cloud mirror source, and mirrorsthe following code is added inside:

    <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>

insert image description here
insert image description here
        In order to check whether the download link of Maven warehouse and Mirror image has been successfully set up, enter in the console mvn help:systemand finally promptBuild SuccessAt the same time, D:\program files\apache-maven-3.8.3\repositorydownload the relevant dependency packages in the warehouse folder, as shown in the figure below.
insert image description here
        There will also be related folders generated under Maven仓库the folder ( D:\program files\apache-maven-3.8.3\repository), and there will be corresponding jarpackage dependencies under the folder ( such as slf4j-api-1.7. 5.jar )
insert image description here
insert image description here

2.3 Gradle configuration

insert image description here

Download the installation package file         on the official website of Gradle , and then put the decompressed folder into the directoryGradle 7.2gradle-7.2-all.zipD:\program files\gradle-7.2
insert image description here
insert image description here
insert image description here

        Then right-click on the computer and select Properties -> Advanced System Settings -> Environment Variables to find the system environment variable Path, add it to its value D:\program files\gradle-7.2\binand confirm, and finally open the cmd window gradle -vto input to verify whether the configuration is successful. If the version number Gradleappears, the configuration is successful.         Next, modify the location of the local warehouse, and set its value by creating a new system environment variable .         In order to ensure the download speed and success rate of the dependent library, it is recommended to create a file under the corresponding folder for the configured domestic image download address , and enter the following content:Gradle
insert image description here
insert image description here
GradleGRADLE_USER_HOMED:\program files\gradle-7.2\GradleRepository\.gradle
insert image description here
insert image description here
GradleGradleGRADLE_USER_HOMEinit.gradle

allprojects {
    
    
    repositories {
    
    
        def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
        all {
    
     ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
    
    
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
    
    
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
            }
        }
        maven {
    
     url ALIYUN_REPOSITORY_URL }
    }
}

insert image description here

3. Spring Boot project example Demo

        参考Spring Quickstart GuideBuilding an Application with Spring Boot

3.1 Using Notepad as IDE

3.1.1 Create a new Spring Boot project managed by Maven and run it as a jar package

        To use the online Spring Initializr to create a new Mavenmanagement Spring Bootproject, you need to make the following settings, Project selection Maven Project, Language selection Java, Spring Boot version selection 2.5.6, Group setting com.example.test, Artifact setting demomavenspringboot, Name setting demomavenspringboot, Description setting Demo project for Spring Boot, Package name setting com.example.test.demomavenspringboot, Packing packaging method selection Jar, Java version selection 8, Dependencies selection on the right Spring Weband click the bottomGenerate, the compressed package file corresponding to the project will be downloadeddemomavenspringboot.zipand unzip to a folder.
insert image description here
insert image description here
insert image description here
insert image description here
        The demomavenspringboot project folder is shown in the figure above, use Notepad Notepadto open the file under src\main\java\com\example\test\demomavenspringboot         Modify the code as shown below, and then in the project root directoryDemomavenspringbootApplication.java
insert image description here
DemomavenspringbootApplication.javaF:\workspace\MydemoSpringBoot\demomavenspringbootStart the cmd command line window and enter the command mvnw spring-boot:runto start the project.

package com.example.test.demomavenspringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemomavenspringbootApplication {
    
    

	public static void main(String[] args) {
    
    
		SpringApplication.run(DemomavenspringbootApplication.class, args);
	}

        @GetMapping("/hello")
        public String hello(@RequestParam(value = "name", defaultValue = "World") String name) 
        {
    
    
                return String.format("Hello %s!", name);
	}
}

insert image description here
insert image description here
        After starting and running, the project will automatically create a new C:\Users\Lenovo.m2 folder (ieC:\Users\your username.m2 folder), there are two folders repository and wrapper under the folder, of whichwrapperfolder is automatically downloaded apache-maven-3.8.3, while therepositoryThe folder stores the relevant dependent jar package files downloaded from the Maven central library during project operation (you can C:\Users\Lenovo\.m2\wrapper\dists\apache-maven-3.8.3-bin\5a6n1u8or3307vo2u2jgmkhm0t\apache-maven-3.8.3\conf文件夹下的settings.xmlcheck it from the file, Note: You can set it to other disk folders according to your own needs to save space on the C disk ).
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
        After the project starts successfully , open Google Chrome and visit http://localhost:8080/ , http://localhost:8080/hello , http://localhost:8080/hello?name=notepad123 in turn , the result is shown in the figure below, Then use the keyboard + and enter in the cmd window to end the operation.CtrlCY

insert image description here
        In order to modify the port number port, you can edit the files under the src\main\resources folder, the content is as follows:application.properties

server.port=8081
server.servlet.context-path=/Notepad

insert image description here
        At the same time, in order to modify the default page, you can create a new file (default page) and file (custom access page) under the src\main\resources\static folder . document contentindex.htmlcesiummyexample.html
index.html

 <!DOCTYPE html>
 <html>
 	<head>
 		<meta charset="UTF-8">
		<title>index.html</title>
	</head>
 	<body>
 		Hello Spring Boot!
	</body>
</html>

insert image description here
cesiummyexample.htmldocument content

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
 </div>
</body>
</html>

insert image description here
        Then use the cmd command line window to start the project in the root directory of the project and then exit , you can use mvnw clean packagethe command to type the project intojar package, and then use the command to run the project in the cmd windowjava -jar xxx.jar , which is simple, trouble-free and highly portable.
insert image description here
insert image description here
        At this time, use Google Chrome to visit http://localhost:8081/Notepad/ , http://localhost:8081/Notepad/cesiummyexample.html , http://localhost:8081/Notepad/hello , http://localhost :8081/Notepad/hello?name=Notepad-SpringBootMaven , the result is shown in the figure below.

insert image description here

3.1.2 Create a new Spring Boot project managed by Gradle and run it as a jar package

        To use the online Spring Initializr to create a new Gradlemanagement Spring Bootproject, you need to make the following settings, Project selection Gradle Project, Language selection Java, Spring Boot version selection 2.5.6, Group setting com.example.test, Artifact setting demogradlespringboot, Name setting demogradlespringboot, Description setting Demo project for Spring Boot, Package name setting com.example.test.demogradlespringboot, Packing packaging method selection Jar, Java version selection 8, Dependencies selection on the right Spring Weband click the bottomGenerate, the compressed package file corresponding to the project will be downloadeddemogradlespringboot.zipand unzip to a folder.
insert image description here
insert image description here
insert image description here
insert image description here
        The demogradlespringboot project folder is shown in the above figure, use Notepad Notepadto open the file under src\main\java\com\example\test\demogradlespringboot         Modify the code as shown below, and then in the project root directoryDemogradlespringbootApplication.java
insert image description here
DemogradlespringbootApplication.javaF:\workspace\MydemoSpringBoot\demogradlespringbootStart the cmd command line window and enter the command gradlew bootRunto start the project.

DemogradlespringbootApplication.java

package com.example.test.demogradlespringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemogradlespringbootApplication {
    
    

	public static void main(String[] args) {
    
    
		SpringApplication.run(DemogradlespringbootApplication.class, args);
	}

        @GetMapping("/hello")
        public String hello(@RequestParam(value = "name", defaultValue = "World") String name) 
        {
    
    
                return String.format("Hello %s!", name);
        }
}

insert image description here
insert image description here
insert image description here
        After starting and running, since GRADLE_USER_HOMEthe value of the system environment variable has been setD:\program files\gradle-7.2\GradleRepository.gradlewrapper, so the project will automatically create new and three folders under this folder , among which the folder will automatically download gradle-7.2 , the folder will store the bin file of gradle , and .tmpthe folder will store the jar package files that the project depends on . After the project starts successfully , open Google Chrome and visit http://localhost:8080/ , http://localhost:8080/hello , http://localhost:8080/hello?name=notepad456 in turn , the result is shown in the figure below, Then use the keyboard + and enter in the cmd window to end the operation.cacheswrapper.tmpcaches
insert image description here
insert image description here
insert image description here
insert image description here
        CtrlCY

insert image description here
        In order to modify the port number port, you can edit the files under the src\main\resources folder, the content is as follows:application.properties

server.port=8082
server.servlet.context-path=/Notepad

insert image description here
        At the same time, in order to modify the default page, you can create a new file (default page) and file (custom access page) under the src\main\resources\static folder . document contentindex.htmlcesiummyexample.html
index.html

 <!DOCTYPE html>
 <html>
 	<head>
 		<meta charset="UTF-8">
		<title>index.html</title>
	</head>
 	<body>
 		Hello Spring Boot!
	</body>
</html>

insert image description here
cesiummyexample.htmldocument content

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
 </div>
</body>
</html>

insert image description here
        Then use the cmd command line window to start the project in the root directory of the project and then exit , you can use gradlew buildthe command to type the project intojar package, and then use the command to run the project in the cmd windowjava -jar xxx.jar , which is simple, trouble-free and highly portable.
insert image description here
insert image description here
        At this time, use Google Chrome to visit http://localhost:8082/Notepad/ , http://localhost:8082/Notepad/cesiummyexample.html , http://localhost:8082/Notepad/hello , http://localhost :8082/Notepad/hello?name=Notepad-SpringBootGradle , the result is shown in the figure below.

insert image description here

3.2 Using Eclipse as IDE

3.2.1 Eclipse configuration Java

        Go to the Eclipse official website to download the eclipse-jee-2021-09-R-win32-x86_64.zip file without installationD:\program files\eclipse2021 , and extract it to a folder here . You can create a new workspace folder
insert image description here
insert image description here
insert image description here
insert image description here
        in the folder, and then double-click to run it. After         starting , select the workspace as the previously customized workspace folder, then create a new project , configure , create a new class under the new package , and in the main function output fromD:\program files\eclipse2021myworkspaceeclipse.exe
insert image description here
EclipseJavaHelloWorldJRE运行时comJavahellohello,world!Test whether the environment configuration of the Java compiler in Eclipse is successful, if the operation is successful, Consolethe console will output text information.
insert image description here

3.2.2 Eclipse configuration Maven

insert image description here
insert image description here

3.2.3 Eclipse Deploy Gradle

Click         in Eclipsethe menu bar , enter the Preference window, click Gradle on the left, and select the local installation directory on the right :WindowsPreferenceGradleLocal installation directoryD:\program files\gradle-7.2, Gradlethe user library directory Gradle user home:D:\program files\gradle-7.2\GradleRepository.gradleAnd Javathe installation directory Java home:D:\Program Files (x86)\Java\jdk1.8.0_221, click ApplyApply.
insert image description here
insert image description here

3.2.4 Eclipse deployment Spring Tools

        In order to Eclipseinstall Springplugins in there are two options:method oneIt is directly selected in the Eclipseupper menu bar . After entering the window and searching , click on the right side of the first one in the lower result list , and keep clicking Next until the installation is complete and prompts to restart ;HelpEclipse MarketPlaceEclipse MarketPlacespring toolsInstalleclipseway twoAfter downloading from the Spring Tools page, go to Eclipse to configure the plug-in. (Note: The first method of installation is introduced and recommended here , which is simple and direct)
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

3.2.5 Create a new Spring Boot project in Eclipse

3.2.5.1 Eclipse creates a new Spring Boot project managed by Maven

        After the installation is complete, you can see the Spring Boot option in the new project using Eclipse.
insert image description here
insert image description here

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
        Run asJava ApplicationYou can choose or choose here Spring Boot App. After the actual test, the running effect is the same on the console, and it can be started.
insert image description here
insert image description here
insert image description here

After opening http://localhost:8080         with a browser , the following page is created successfully; at the same time, accessing http://localhost:8080/hello will print Hello World!; accessing http://localhost:8080/hello?name=csdn123 will printHello csdn123!

insert image description here


        If you want to modify Tomcatthe access port number (default 8080), you need to application.propertiesedit the file, or you can change the suffix name ymlto edit it. Also need to pom.xmladd maven-resources-plugindependencies in.

<dependency>
  		<groupId>org.apache.maven.plugins</groupId>
  		<artifactId>maven-resources-plugin</artifactId>
  		<version>3.2.0</version>
</dependency>

insert image description here
application.propertiesThe content of the file is as follows:

server.port=8081
server.servlet.context-path=/csdn

insert image description here

application.ymlThe content of the file is as follows:

server:
  #端口号
  port: 8081
  #项目名,如果不设定,默认是 /
  servlet:
    context-path: /csdn

insert image description here
        After saving and running, you can see that the port number port and context path have been successfully modified, and then visit the following three links in the browser: http://localhost:8081/csdn/ , http://localhost:8081/ csdn/hello , http://localhost:8081/csdn/hello?name=csdn123

insert image description here
insert image description here


        If you want to make a welcome page, you resourcescan staticcreate a new index.htmlfile in the following, the content of the file is as follows:

 <!DOCTYPE html>
 <html>
 	<head>
 		<meta charset="UTF-8">
		<title>index.html</title>
	</head>
 	<body>
 		Hello Spring Boot!
	</body>
</html>

insert image description here

        Then with a curious attitude, I tried to create a new cesiummyexample.htmlfile under the static folder, and found that I could visit http://localhost:8081/csdn/cesiummyexample.htmlSpringBoot in the browser after startup , which is really good.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
</body>
</html>

insert image description here
insert image description here

3.2.5.2 Eclipse creates a SpringBoot project managed by Gradle

        Open it , select File->New->OtherEclipse in the menu bar , and a pop-up window will pop up, select the next one and click , enter the project name         in the window , and then select the type Type , Packaging selection , Java Version selection , Language language selection , and the rest You can customize it, then click to pop up the New Spring Starter Project Dependencies window, select the Spring Boot version ( note that it is not recommended to choose the SNAP-SHOT version), check it and click it.         Note: In fact, in essence, the property setting of the new project is ultimately to piece together a URL download link of the eclipse_SpringBoot2 project to obtain the set Spring Boot project , because the root is essentially fromSelect a wizardSpring BootSpring Starter ProjectNext
insert image description here
insert image description here
New Spring Starter Projecteclipse_SpringBoot2Gradle ProjectJar8JavaNext2.5.6WebSpring WebFinish
insert image description here
insert image description here
EclipseSpring BootSpring Initializer to download. But it is still Eclipsemore convenient and faster to use here.
insert image description here

https://start.spring.io/starter.zip?name=eclipse_SpringBoot2&groupId=my.test&artifactId=eclipse_SpringBoot2&version=0.0.1-SNAPSHOT&description=Demo+project+for+Spring+Boot&packageName=my.test.mydemo&type=gradle-project&packaging=jar&javaVersion=1.8&language=java&bootVersion=2.5.6&dependencies=web

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
        After starting and running, open the browser and visit http://localhost:8080/ , http://localhost:8080/hello , http://localhost:8080/hello?name=csdn456 in turn , and you can see the following results to Gradlemanage Spring Bootthe project Created and run successfully.
insert image description here


        If you want to modify the port number portand default page, you can application.propertiesedit the file, and create a new file and cesiummyexample.html file in the folder under src/main/resources , and then start it again. document:staticindex.html
application.properties

server.port=8082
server.servlet.context-path=/CSDN

index.html file:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Welcome to CSDN</title>
	</head>
	<body>
		Hello,I'm CSDN! Welcome you!
	</body>
</html>

Cesiummyexample.html file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
</body>
</html>

insert image description here

http://localhost:8082/CSDN

http://localhost:8082/CSDN/hello

http://localhost:8082/CSDN/hello?name=csdn456

http://localhost:8082/CSDN/cesiummyexample.html
insert image description here

3.3 Using VSCode as IDE

insert image description here

        Go to the VSCode official website to download the Windows x64-bit installation package VSCodeUserSetup-x64-1.61.2.exe , double-click to install it directly.
insert image description here

insert image description here

3.3.1 VSCode configuration Java

        Open Visual Studio Code, click the extension (Ctrl+Shift+X) under View in the menu bar to pop up the extension search box to enter Java Extension Pack, find the search result and install it.
insert image description here
insert image description here
insert image description here
        In order to configure the Java runtime environment in VSCode, click the setting icon in the lower left corner of VSCode to enter the settings, enter in the upper text box to open the java.configuration.runtimesfile settings.json, edit the content as follows:
insert image description here
insert image description here
insert image description here
        enter to Java: Create New Projectcreate a Java project, then click No Build Tools, select the workspace folder, the project After entering the name, FirstJavaApplicationpress Enter to confirm.
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

3.3.2 VSCode configuration Maven

        First click on VSCodethe extension under View in the menu bar. After opening the extension window, Maven for Javainstall the Maven plug-in by searching
insert image description here
insert image description here
        and then click VSCodethe setting icon in the lower left corner to enter the setting. After typing in the text box above, java.configuration.mavenclick Java to configure the global settings and user settings on the right. Just point to the files in the folder under the local installation directory (MavenMavenconfsettings.xmlD:\program files\apache-maven-3.8.3\conf\settings.xml)。
insert image description here

3.3.3 VSCode configuration Gradle

        First click VSCodethe extension under View in the menu bar, open the extension window, and Gradle Extension Packinstall the Gradle plug-in by searching
insert image description here

3.3.4 VSCode configuration Spring Tools

        First click on VSCodethe extension under View in the menu bar, open the extension window, and Spring Boot Extension Packinstall the Spring Boot plug-in by searching
insert image description here

3.3.5 Create Spring Boot project in VSCode

3.3.5.1 VSCode creates a Spring Boot project managed by Maven

        Open it VSCode, click View All Commands in Help in the menu bar , enter in the command box and press Enter, and then set the properties of the project: Select Spring Boot Version , select Project Language , enter Group Id and press Enter, and enter Artifact Id Press Enter, select Packing Type , Java Version , Choose Dependencies , finally select the workspace and confirm, wait for the project initialization to complete .         After the project initialization is completed, edit the src->main->java->com.example.mytest.demospringbootmaven         as shown in the figure below . The edited code is as follows, and then right-click to run.Spring Initializr: Create a Maven Project2.5.6Javacom.example.mytestdemospringmavenJar8Spring WebD:\program files\Microsoft VS Code\myworkspace
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description here
DemospringbootmavenApplication.javaRun Java

package com.example.mytest.demospringbootmaven;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemospringbootmavenApplication {
    
    

	public static void main(String[] args) {
    
    
		SpringApplication.run(DemospringbootmavenApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
    
    
		return String.format("Hello %s!", name);
	}
}

insert image description here
insert image description here
        You can see that the Spring Boot project runs successfully. At this time, open Google Chrome and visit http://localhost:8080/ , http://localhost:8080/hello , http://localhost:8080/hello?name=vscode123 , The result is shown in the figure below.
insert image description here


        If you want to modify the port number portand default page, you can application.propertiesedit the file, and create a new file and file under the folder under src/main/resources , and then start the operation again. document:staticindex.htmlcesiummyexample.html
application.properties

server.port=8081
server.servlet.context-path=/VSCode

insert image description here

index.htmldocument:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Welcome to VSCode</title>
    </head>
    <body>
        Hello,I'm MavenSpringBoot Application in VSCode!
    </body>
</html>

insert image description here
cesiummyexample.htmldocument:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
</body>
</html>

insert image description here
insert image description here
        After the project starts, the browser visits http://localhost:8081/VSCode/

http://localhost:8081/VSCode/cesiummyexample.html
insert image description here
http://localhost:8081/VSCode/hello

http://localhost:8081/VSCode /hello?name=vscode456

3.3.5.2 VSCode creates a Spring Boot project managed by Gradle

        Open it VSCode, click View All Commands in Help in the menu bar , enter in the command box and press Enter, and then set the properties of the project: Select Spring Boot Version , select Project Language , enter Group Id and press Enter, and enter Artifact Id Press Enter, select Packing Type , Java Version , Choose Dependencies , finally select the workspace and confirm, wait for the project initialization to complete . After the project initialization is complete ,         you can use VS to reopen the demospringgradle folder and edit it under src->main->java->com.example.mytest.demospringbootgradle as shown in the figure below. The edited code is as follows, and then right-click         to run .Spring Initializr: Create a Gradle Project2.5.6Javacom.example.mytestdemospringgradleJar8Spring WebD:\program files\Microsoft VS Code\myworkspace
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description here
DemospringgradleApplication.javaRun Java

package com.example.mytest.demospringgradle;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemospringgradleApplication {
    
    

	public static void main(String[] args) {
    
    
		SpringApplication.run(DemospringgradleApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
    
    
		return String.format("Hello %s!", name);
	}
}

insert image description here
insert image description here
        You can see that the Spring Boot project runs successfully. At this time, open Google Chrome and visit http://localhost:8080/ , http://localhost:8080/hello , http://localhost:8080/hello?name=vscode- gradle123 , the result is shown in the figure below.
insert image description here


        If you want to modify the port number portand default page, you can application.propertiesedit the file, and create a new file and file under the folder under src/main/resources , and then start the operation again. document:staticindex.htmlcesiummyexample.html
application.properties

server.port=8082
server.servlet.context-path=/VSCode

insert image description here
index.htmldocument:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Welcome to VSCode</title>
    </head>
    <body>
        Hello,I'm GradleSpringBoot Application in VSCode!
    </body>
</html>

insert image description here
cesiummyexample.htmldocument:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
</body>
</html>

insert image description here
insert image description here
        After the project starts, the browser visits http://localhost:8082/VSCode/

http://localhost:8082/VSCode/
insert image description here
http://localhost:8082/VSCode/hello

http://localhost:8082/VSCode/hello? name=vscode-gradle456

3.4 Using IDEA as IDE

insert image description here

insert image description here
insert image description here
insert image description here

        Go to the IDEA official website to download the trial version or purchase the professional version for installation to experience more complete Java Web Enterprise Edition development functions.

3.4.1 IDEA Deploy Java

insert image description here
        Open IDEA, and then click the next in the lower right corner Configure, Structure for New Projectsa pop-up Project Sturcture for New Projectswindow, click on the left side of the window SDKsand click in the middle +to select JDKthe directoryD:\Program Files (x86)\Java\jdk1.8.0_221, you can see Classpaththat there is a jar package file in the corresponding JDK directory .
insert image description here

3.4.2 IDEA Deployment Maven

insert image description here

insert image description here

        Open it IDEA, and then click in the lower right corner Configureto Settingspop up a window, select Build Tools under Build, Execution, Deployment on Settings for New Projectsthe left side of the window , and set the installation directory on the right side toMavenMavenMaven home directoryD:/program files/apache-maven-3.8.3 , the user settings file User setting fileisD:\program files\apache-maven-3.8.3\conf\settings.xml, the local Mavenlibrary directory Local repositoryis set toD:\program files\apache-maven-3.8.3\repository, click the lower right corner Apply-> OK to apply the settings.
insert image description here

3.4.3 IDEA Deployment Gradle

insert image description here

insert image description here

        Open it IDEA, and then click in the lower right corner Configureto Settingspop up a window, select Build Tools under Build, Execution, DeploymentSettings for New Projects on the left side of the window , and set the local user library directory toGradleGradleGradle user homeD:\program files\gradle-7.2\GradleRepository.gradle, click the lower right corner Apply-> OK to apply the settings.
insert image description here

3.4.4 IDEA Deployment Spring Tools

        Open it IDEA, and then click in the lower right corner Configure, Pluginsa pop-up window, enter Spring ToolsPlugins in the search box and click Install , and then you can see under Installed , and other extensions have been installed.InstallSpring ToolsMavenGradle

insert image description here
insert image description here

3.4.5 IDEA creates a Spring Boot project

3.4.5.1 IDEA creates a Spring Boot project managed by Maven

        Open it IDEA, click to Create New Projectcreate a new project, and a pop-up New Projectwindow will pop up, select the left side, and then select the local Project SDKSpring Initializer on the right side by default , select the default URL https://start.spring.io at the bottom and click .         In the New Project window, set some properties of the project (such as Group customization, Artifact customization, Type selection , Language selection , Packing packaging method selection , Java Version selection , Version customization filling, Name writing , Description customization, Package Package name is automatically generated) and click , and then click after selecting DependenciesJava JDK 1.8Next
insert image description here
insert image description here
Spring Initializer Project SettingsMaven ProjectJavaJar8demomavenspringNextWebSpring WebNext, and finally check the project name Project Name, project location , and module settings Project Locationbelow , and then click .         After the project is created, as shown in the figure below, inModule SettingsFinish
insert image description here
insert image description here
insert image description here
src-main-java-com.example.demomavenspringDemomavenspringApplication.javaRight-click to run Run 'DemomavenspringApplication' after editing the code below , and then Consolesee the project running and starting results in the console.
insert image description here

package com.example.demomavenspring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemomavenspringApplication {
    
    

    public static void main(String[] args)
    {
    
    
        SpringApplication.run(DemomavenspringApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
    
    
        return String.format("Hello %s!", name);
    }
}

insert image description here
insert image description here
insert image description here
        At this time, open Google Chrome and visit http://localhost:8080 , http://localhost:8080/hello , http://localhost:8080/hello?name=IDEAMavenSpring in turn , and the result is shown in the figure below.
insert image description here


        If you want to modify the port number portand default page, you can application.propertiesedit the file, and create a new file and file under the folder under src/main/resources , and then start the operation again. document:staticindex.htmlcesiummyexample.html
application.properties

server.port=8081
server.servlet.context-path=/IDEA

index.htmldocument:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Welcome to IDEA</title>
    </head>
    <body>
        Hello,I'm MavenSpringBoot Application in IDEA!
    </body>
</html>

cesiummyexample.htmldocument:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
</body>
</html>

insert image description here
insert image description here
insert image description here
insert image description here
        After the project starts, the browser visits http://localhost:8081/IDEA/

http://localhost:8081/IDEA/cesiummyexample.html
insert image description here
http://localhost:8081/IDEA/hello

http://localhost:8081/IDEA /hello?name=IDEAmavenSpringBoot

3.4.5.2 IDEA creates a Spring Boot project managed by Gradle

        Open it IDEA, click to Create New Projectcreate a new project, and a pop-up New Projectwindow will pop up, select the left side, and then select the local Project SDKSpring Initializer on the right side by default , select the default URL https://start.spring.io at the bottom and click .         In the New Project window, set some properties of the project (such as Group customization, Artifact customization, Type selection , Language selection , Packing packaging method selection , Java Version selection , Version customization filling, Name writing , Description customization, Package Package name is automatically generated) and click , and then click after selecting DependenciesJava JDK 1.8Next
insert image description here
insert image description here
Spring Initializer Project SettingsGradle ProjectJavaJar8demogradlespringNextWebSpring WebNext, and finally check the project name Project Name, project location , and module settings Project Locationbelow , and then click .         After the project is created, as shown in the figure below, inModule SettingsFinish
insert image description here
insert image description here
insert image description here
src-main-java-com.example.demomavenspringDemogradlespringApplication.javaAfter editing the code below , right-click to run Run 'DemogradlespringApplication', and then Consolesee the project running and starting results in the console.
insert image description here
insert image description here
insert image description here
insert image description here
        At this time, open Google Chrome and visit http://localhost:8080 , http://localhost:8080/hello , http://localhost:8080/hello?name=IDEAGradleSpring in turn , and the result is shown in the figure below.
insert image description here


        If you want to modify the port number portand default page, you can application.propertiesedit the file, and create a new file and file under the folder under src/main/resources , and then start the operation again. document:staticindex.htmlcesiummyexample.html
application.properties

server.port=8082
server.servlet.context-path=/IDEA

index.htmldocument:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Welcome to IDEA</title>
    </head>
    <body>
        Hello,I'm GradleSpringBoot Application in IDEA!
    </body>
</html>

cesiummyexample.htmldocument:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <!-- Include the CesiumJS JavaScript and CSS files -->
  <script src="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Cesium.js"></script>
  <link href="https://cesium.com/downloads/cesiumjs/releases/1.86/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Your access token can be found at: https://cesium.com/ion/tokens.
    // Replace `your_access_token` with your Cesium ion access token.

    Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZDdhNmRjMC0yNGMxLTRlYWItYjU5Ny1jZjJjZWIyNWI2YmIiLCJpZCI6NzY2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU1MDExMjI4NH0.e_LkplBoPjo_fSqLsGAb97ypotS0G5tMHJoSxLkqyUw';

    // Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      
      
      terrainProvider: Cesium.createWorldTerrain()
    });    
    // Add Cesium OSM Buildings, a global 3D buildings layer.
    const buildingTileset = viewer.scene.primitives.add(Cesium.createOsmBuildings());   
    // Fly the camera to San Francisco at the given longitude, latitude, and height.
    viewer.camera.flyTo({
      
      
      destination : Cesium.Cartesian3.fromDegrees(-122.4175, 37.655, 400),
      orientation : {
      
      
        heading : Cesium.Math.toRadians(0.0),
        pitch : Cesium.Math.toRadians(-15.0),
      }
    });
  </script>
</body>
</html>

insert image description here
insert image description here
insert image description here
insert image description here

        After the project starts, the browser visits http://localhost:8082/IDEA/

http://localhost:8082/IDEA/cesiummyexample.html
insert image description here
http://localhost:8082/IDEA/hello

http://localhost:8082/IDEA /hello?name=gradleSpring

4、Spring Boot CLI

        Spring Boot CLIis a command-line tool that can be used to quickly develop Springapplications, allows running Groovyscripts, and can use familiar similar Javasyntax without much boilerplate code to bootstrap a new project or write custom commands for it. Spring Boot CLI 2.6.0 download address , unzip the file and open the INSTALL.txt file, prompting that Java needs to be installed, you can enter it in the cmd windowjava -version to test whether the Java environment configuration is complete.

insert image description here
insert image description here
        Then right click on the computer->Properties->Advanced System Settings->Environment Variables, create a new system environment variable SPRING_HOME, set its value toD:\Program Files (x86)\spring-2.6.0-SNAPSHOT, and then find under the system environment variable Path, add it to it %SPRING_HOME%\binand confirm.
insert image description here
insert image description here
        Refer to the Spring Boot CLI documentation to learn common commands.
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/jing_zhong/article/details/120833537