Akik: : Have you been paying attention?

Making: making

CSDN: Check it out??

Hobby: Americano More Ice!

Hand to hand away your first time, writespringbootproject

The initial code is generated from spring.io, configured as follows

Download a. Zip file, extract the import IDEA can start, this is the basic project structure

Let’s open the SRC/main/Java/geektime/spring/hello/hellospring/HelloSpringApplication. Java, modified to the following code

package geektime.spring.hello.hellospring;

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

@SpringBootApplication
@RestController
public class HelloSpringApplication {

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

	@RequestMapping("/hello")
	public String hello(a) {
		return "Hello Spring"; }}Copy the code

Then run our modified code, and when it succeeds, the console prints the following message

/ Library/Java/JavaVirtualMachines/JDK - 15.0.1. JDK/Contents/Home/bin/Java - javaagent: / Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=55568:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/lidean/Downloads/hello-spring/target/classes:/Users/lidean/.m2/repository/org/springframework/boot/spring-boot-st Arter - physical / 2.5.0 / spring - the boot - starter - physical - 2.5.0. Jar: / Users/lidean/m2 / repository/org/springframework/boot/spring - the boot - starter / 2.5.0 / spring - the boot - starter - 2.5.0. Jar: / Users/lidean/m2 / repository/org/springframework/boot/spring - the boot / 2.5. 0 / spring - the boot - 2.5.0. Jar: / Users/lidean/m2 / repository/org/springframework/boot/spring - the boot - autoconfigure / 2.5.0 / spring - boo T - autoconfigure - 2.5.0. Jar: / Users/lidean/m2 / repository/org/springframework/boot/spring - the boot - starter - logging / 2.5.0 / spring - the boot - starter - logging - 2.5.0. Jar: / Users/lidean/m2 / repository/ch/qos/logback/logback - classic / 1.2.3 logback - classic - 1.2.3. Jar: / Users/lidean/m2 / repository/ch/qos/logback/logback - core / 1.2.3 / logback - core - 1.2.3. Jar: / Users/lidean/m2 / repository/o Rg/apache/logging/log4j/log4j - to - slf4j / 2.14.1 / log4j - to - slf4j - 2.14.1. Jar: / Users/lidean/m2 / repository/org/apache/logging / Log4j/log4j - API / 2.14.1 log4j - API - 2.14.1. Jar: / Users/lidean/m2 / repository/org/slf4j/jul - to - slf4j / 1.7.30 / jul - to - slf4j - 1.7. 30. Jar: / Users/lidean/m2 / repository/Jakarta/annotation/Jakarta. The annotation - API / 1.3.5 / Jakarta. The annotation - API - 1.3.5. Jar: / Us Ers/lidean/m2 / repository/org/yaml/snakeyaml / 1.28 / snakeyaml - 1.28. The jar: / Users/lidean/m2 / repository/org/springframework/bo Ot/spring - the boot - physical - autoconfigure / 2.5.0 / spring - the boot - physical - autoconfigure - 2.5.0. Jar: / Users/lidean/m2 / repository/or G/springframework/boot/spring - the boot - physical / 2.5.0 / spring - the boot - physical - 2.5.0. Jar: / Users/lidean/m2 / repository/com/faster - XML/Jackson/core/Jackson - databind 2.12.3 / Jackson - databind - 2.12.3. Jar: / Users/lidean/m2 / repository/com/fasterxml/Jackson / The core/Jackson - annotations / 2.12.3 / Jackson - annotations - 2.12.3. Jar: / Users/lidean/m2 / repository/com/fasterxml/Jackson/core/j Ackson - core / 2.12.3 / Jackson - core - 2.12.3. Jar: / Users/lidean/m2 / repository/com/fasterxml/Jackson/datatype/Jackson -- datatype Jsr310/2.12.3 / Jackson - datatype - jsr310-2.12.3. Jar: / Users/lidean/m2 / repository/IO/micrometer micrometer - core / 1.7.0 / microm Eter - core - 1.7.0. Jar: / Users/lidean/m2 / repository/org/hdrhistogram/hdrhistogram / 2.1.12 / hdrhistogram - 2.1.12. Jar: / Users/lid Ean/m2 / repository/org/latencyutils/latencyutils / 2.0.3 / latencyutils - 2.0.3. Jar: / Users/lidean/m2 / repository/org/springfra Mework/boot/spring - the boot - starter - web / 2.5.0 / spring - the boot - starter - web - 2.5.0. Jar: / Users/lidean/m2 / repository/org/springframe Work/boot/spring - the boot - starter - json / 2.5.0 / spring - the boot - starter - json - 2.5.0. Jar: / Users/lidean/m2 / repository/com/fasterxml/j Ackson datatype/Jackson - datatype - jdk8/2.12.3 / Jackson - datatype - jdk8-2.12.3. Jar: / Users/lidean/m2 / repository/com/fasterxml Jackson/module/Jackson - module - parameter - names / 2.12.3 / Jackson - module - parameter - names - 2.12.3. Jar: / Users/lidean/m2 / reposi Tory/org/springframework/boot/spring - the boot - starter - tomcat / 2.5.0 / spring - the boot - starter - tomcat - 2.5.0. Jar: / Users/lidean/m2 / re Pository/org/apache/tomcat/embed tomcat - embed - core / 9.0.46 / tomcat - embed - core - 9.0.46. Jar: / Users/lidean/m2 / repository/org Apache tomcat/embed/tomcat - embed - el / 9.0.46 / tomcat - embed - el - 9.0.46. Jar: / Users/lidean/m2 / repository/org/apache/tomcat/emb Ed/tomcat - embed - websocket / 9.0.46 / tomcat - embed - websocket - 9.0.46. Jar: / Users/lidean/m2 / repository/org/springframework/spri Ng - web / 5.3.7 / spring - web - 5.3.7. Jar: / Users/lidean/m2 / repository/org/springframework/spring beans / 5.3.7 / spring beans -- 5.3.7 Jar: / Users/lidean/m2 / repository/org/springframework/spring - webmvc / 5.3.7 / spring - webmvc - 5.3.7. Jar: / Users/lidean/m2 / repo Sitory/org/springframework/spring aop / 5.3.7 / spring aop -- 5.3.7. Jar: / Users/lidean/m2 / repository/org/springframework/spring - the context / 5.3.7 / spring - the context - 5.3.7. Jar: / Users/lidean/m2 / repository/org/springframework/spring - expression / 5.3.7 / spring - Expression - 5.3.7. Jar: / Users/lidean/m2 / repository/org/slf4j/slf4j - API / 1.7.30 / slf4j - API - 1.7.30. Jar: / Users/lidean/m2 / repo Sitory/org/springframework/spring core / 5.3.7 / spring - core - 5.3.7. Jar: / Users/lidean/m2 / repository/org/springframework/spri Ng - JCL / 5.3.7 / spring - the JCL - 5.3.7. Jar geektime. Spring. Hello. Hellospring. HelloSpringApplication. ____ _ __ _ _ / \ \ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \ / _ ` | \ \ \ \ \ \ / ___) | | _) | | | | | | | (_ | |))))' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.0) 23:15:57 2021-06-01. 81444-484 the INFO [main] G.S.H.H.H elloSpringApplication: Starting HelloSpringApplication using Java 15.0.1 on macBook-pro-9. local with PID 81444 (/Users/lidean/Downloads/hello-spring/target/classes started by lidean in /Users/lidean/Downloads/hello-spring) The 2021-06-01 23:15:57. 81444-488 the INFO [the main] G.S.H.H.H elloSpringApplication: No active profile set, falling back to default profiles: The default 23:15:58 2021-06-01. 81444-610 the INFO [main] O.S.B.W.E mbedded. Tomcat. TomcatWebServer: Tomcat initialized with port(s): 8080 (HTTP) 23:15:58 2021-06-01. 81444-626 the INFO [main] o.a pache, catalina. Core. StandardService: Starting the service [Tomcat] 2021-06-01 23:15:58. 626 INFO 81444 - [the main] org. Apache. Catalina. Core. StandardEngine: Starting Servlet engine: [Apache Tomcat/9.0.46] 2021-06-01 23:15:58.685 INFO 81444 -- [main] O.A.C.C.C. [Tomcat].[localhost].[/] : Initializing Spring Embedded WebApplicationContext 2021-06-01 23:15:58.685 INFO 81444 -- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: Initialization completed in 1073 ms 23:15:59 2021-06-01. 81444-156 the INFO [main] O.S.B.A.E.W eb. EndpointLinksResolver:  Exposing 1 endpoint(s) beneath base path '/actuator'81444-2021-06-01 23:15:59. 195 INFO [main] O.S.B.W.E mbedded. Tomcat. TomcatWebServer: tomcat is started on the port (s) : 8080 (http) with context path ''81444-2021-06-01 23:15:59. 208 INFO [main] G.S.H.H.H elloSpringApplication: Started HelloSpringApplication in 2.658 seconds (JVM running for 3.251) 2021-06-01 23:15:59.254 INFO 81444 -- [main] o.s.b.a.ApplicationAvailabilityBean : Application Availability State LivenessState Changed to CORRECT 2021-06-01 23:15:59.256 INFO 81444 -- [main] o.s.b.a.ApplicationAvailabilityBean : Application Availability State ReadinessState Changed to ACCEPTING_TRAFFIC 2021-06-01 23:22:00.698 INFO 81444 -- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'81444-2021-06-01 23:22:00. 698 INFO [nio - 8080 - exec - 1] O.S.W eb. Servlet. The DispatcherServlet: Initializing the servlet'dispatcherServlet'
2021-06-01 23:22:00.699  INFO 81444 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
Copy the code

Tomcat is initially deployed on port 8080

We define the router $/ / call the curl http://127.0.0.1:8080/hello Hello Spring % / / remember our previous generation projects using physical dependence, is used to check whether the project is health / / if the DOWN, We visit the url will fail ${curl http://127.0.0.1:8080/actuator/health"status":"UP"} %Copy the code

Have Maven pack it for us

$ mvn clean packeage -Dmaven.test.skip
zsh: command not found: mvn
Copy the code

No orders… On the link

If yes, skip it

The author uses ZSH for macOs and needs to do the following steps

Give folder permissions
$ sudo chown -R root:wheel Downloads/apache-maven*
# mobile
$ mv Downloads/apache-maven* /opt/apache-maven
Open the ZSH configuration file
$ nano ~/.zshrc
ZSHRC ~/.zshrc
$ export PATH=$PATH:/opt/apache-maven/bin
Copy the code

Control +X press Enter to restart the terminal and check the MVN version

$ zsh
# check Maven$MVN - version Apache Maven 3.8.1 c21c65bdfed0f71a2f2ada8b84da59348c4c5d (05) Maven home: /opt/ apache-Maven Java version: 15.0.1, Vendor: Oracle Corporation, Runtime: / Library/Java/JavaVirtualMachines/JDK - 15.0.1. JDK/Contents/Home Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.6", arch: "x86_64", family: "mac"
Copy the code

Moving on, Maven packages our code

$ mvn clean package -Dmaven.test.skip 
[INFO] Scanning forprojects... [INFO] [INFO] -----------------< geektime.spring.hello:hello-spring >----------------- [INFO] Building hello-spring 0.0.1 - the SNAPSHOT [INFO] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (jar) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [INFO] - [INFO] Maven - clean - plugin: 3.1.0: clean (default - the clean) @ hello - spring - [INFO] Deleting / Users/lidean/Downloads/hello - spring/target/INFO/INFO maven - resources - the plugin: 3.2.0: resources (default - resources)  @ hello-spring --- [INFO] Using'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8'encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 0 resource [INFO] [INFO] --- Maven-compiler-plugin :3.8.1:compile (default-compile) @ helo-spring -- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1sourceThe file to/Users/lidean/Downloads/hello - spring/target/classes/INFO/INFO maven - resources - the plugin: 3.2.0: testResources  (default-testResources) @ hello-spring --- [INFO] Not copyingtestResources [INFO] [INFO] -- maven-compiler-plugin:3.8.1:testCompile (default-testcompile) @hell-spring -- [INFO] Not compilingtestSources [INFO] [INFO] -- Maven-Surefire-plugin :2.22.2: Sources [INFO] [INFO] -- Sources [INFO] -- Maven-Surefire-plugin :2.22.2:test(default-test) @hello-spring -- [INFO] Tests are skipped. [INFO] [INFO] -- Maven-jar-plugin :3.2.0:jar (default-jar) @  hello-spring --- [INFO] Building jar: / Users/lidean/Downloads/hello - spring/target/hello - spring - 0.0.1 - the SNAPSHOT. Jar [INFO] - [INFO] Spring-boot-maven-plugin :2.5.0: Repackage (Repackage) @hello-Spring -- [INFO] Replacing main artifact with Repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [INFO] Total time: 2.965 s [INFO] Finished at: 2021-06-02T00:02:00+08:00 [INFO] ------------------------------------------------------------------------Copy the code

You can see the two.jar packages generated, one 18M and one 3.0K, because the former has all our dependencies (the.jar package is executable) and the latter is the original package

The java-jar package is also exposed to port 8080, which allows our program to run as a separate process

Conclusion: if encounter what question or suggestion, can leave a message comment directly! The author will reply immediately

If you feel small white this article is good or helpful to you, look forward to your one key three even 💫! ❤ ️ ni ~