learning spring for Init Project
Posted 良红
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了learning spring for Init Project 相关的知识,希望对你有一定的参考价值。
reference:https://spring.io/quickstart
内容概要:
1 .初始化工程:
首先打开Idea软件, File->New->Project,如下图所示:
选中上图Spring Assistant,这是一个插件用来初始化spring工程。点击上图下一步,如下图所示:
点击Next.如下图所示:
选中上图的Web->Spring Web,然后点击Next,如下图所示:
输入项目名称,选项工程存放路径,点击Next. 如下图所示:
等待工程自动下载相关的jar包,结果如下图所示:
2.提交初始化工程至git 仓库当中:
E:\\share\\spring-helloworld>git init
Initialized empty Git repository in E:/share/spring-helloworld/.git/
E:\\share\\spring-helloworld>git add *
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/MavenWrapperDownloader.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/maven-wrapper.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.cmd.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/java/com/example/demo/DemoApplication.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/resources/application.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/test/java/com/example/demo/DemoApplicationTests.java.
The file will have its original line endings in your working directory.
E:\\share\\spring-helloworld>git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: .mvn/wrapper/MavenWrapperDownloader.java
new file: .mvn/wrapper/maven-wrapper.jar
new file: .mvn/wrapper/maven-wrapper.properties
new file: mvnw
new file: mvnw.cmd
new file: pom.xml
new file: src/main/java/com/example/demo/DemoApplication.java
new file: src/main/resources/application.properties
new file: src/test/java/com/example/demo/DemoApplicationTests.java
E:\\share\\spring-helloworld>git commit -m "first commit"
[master (root-commit) d9a9213] first commit
10 files changed, 718 insertions(+)
create mode 100644 .gitignore
create mode 100644 .mvn/wrapper/MavenWrapperDownloader.java
create mode 100644 .mvn/wrapper/maven-wrapper.jar
create mode 100644 .mvn/wrapper/maven-wrapper.properties
create mode 100644 mvnw
create mode 100644 mvnw.cmd
create mode 100644 pom.xml
create mode 100644 src/main/java/com/example/demo/DemoApplication.java
create mode 100644 src/main/resources/application.properties
create mode 100644 src/test/java/com/example/demo/DemoApplicationTests.java
E:\\share\\spring-helloworld>git remote add origin https://gitee.com/yilianghong/spring-helloworld.git
E:\\share\\spring-helloworld>git push -u origin master
Counting objects: 26, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (26/26), 52.38 KiB | 10.48 MiB/s, done.
Total 26 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/yilianghong/spring-helloworld.git
* [new branch] master -> master
Branch \'master\' set up to track remote branch \'master\' from \'origin\'.
E:\\share\\spring-helloworld>git log
commit d9a9213deaa5837ead3aa3c2ff43f5817d5eff19 (HEAD -> master, origin/master)
Author: panzidong <642936744@qq.com>
Date: Tue Mar 3 09:45:03 2020 +0800
first commit
E:\\share\\spring-helloworld>
3. Support /hello route access
add code
run project:
E:\\share\\spring-helloworld>mvn spring-boot:run [WARNING] [WARNING] Some problems were encountered while building the effective settings [WARNING] expected START_TAG or END_TAG not TEXT (position: TEXT seen ...<mirrors>\\r\\n<mirror>\\r\\n\\u3000\\u3000 <i... @5:6) @ C:\\Users\\admin\\.m2\\settings.xml, line 5, column 6 [WARNING] [INFO] Scanning for projects... [INFO] [INFO] --------------------------< com.example:demo >-------------------------- [INFO] Building demo 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] >>> spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) > test-compile @ demo >>> [INFO] [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo --- [INFO] Using \'UTF-8\' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to E:\\share\\spring-helloworld\\target\\classes [INFO] [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo --- [INFO] Using \'UTF-8\' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory E:\\share\\spring-helloworld\\src\\test\\resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to E:\\share\\spring-helloworld\\target\\test-classes [INFO] [INFO] <<< spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) < test-compile @ demo <<< [INFO] [INFO] [INFO] --- spring-boot-maven-plugin:2.2.5.RELEASE:run (default-cli) @ demo --- [INFO] Attaching agents: [] . ____ _ __ _ _ /\\\\ / ___\'_ __ _ _(_)_ __ __ _ \\ \\ \\ \\ ( ( )\\___ | \'_ | \'_| | \'_ \\/ _` | \\ \\ \\ \\ \\\\/ ___)| |_)| | | | | || (_| | ) ) ) ) \' |____| .__|_| |_|_| |_\\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.2.5.RELEASE) 2020-03-03 10:04:49.041 INFO 15828 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on PC-panzidong with PID 15828 (E:\\share\\spring-helloworld\\target\\classes started by admin in E:\\share\\spring-helloworld) 2020-03-03 10:04:49.043 INFO 15828 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default 2020-03-03 10:04:50.079 INFO 15828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2020-03-03 10:04:50.091 INFO 15828 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-03-03 10:04:50.092 INFO 15828 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31] 2020-03-03 10:04:50.173 INFO 15828 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-03-03 10:04:50.173 INFO 15828 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1070 ms 2020-03-03 10:04:50.316 INFO 15828 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService \'applicationTaskExecutor\' 2020-03-03 10:04:50.435 INFO 15828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path \'\' 2020-03-03 10:04:50.438 INFO 15828 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.737 seconds (JVM running for 2.046) 2020-03-03 10:04:56.996 INFO 15828 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet \'dispatcherServlet\' 2020-03-03 10:04:56.996 INFO 15828 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet \'dispatcherServlet\' 2020-03-03 10:04:57.004 INFO 15828 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 8 ms
result:
http://localhost:8080/hello?name=Amy
以上是关于learning spring for Init Project 的主要内容,如果未能解决你的问题,请参考以下文章
项目中访问controller报错:HTTP Status 500 - Servlet.init() for servlet spring threw exception
Servlet.init() for servlet [spring-dispatcher] threw exception
HTTP Status 500 - Servlet.init() for servlet springmvc threw exception