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 <[email protected]>
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

http://localhost:8080/hello?name=Amy

原文地址:https://www.cnblogs.com/lianghong881018/p/12400702.html

时间: 2024-08-29 23:32:28

learning spring for Init Project (一)的相关文章

On the way learning spring 2

Spring 10 - Bean scope Prototype; Request ;Session; Singleton. Source Code: Person person1 = (Person) context.getBean("person"); Person person2 = (Person) context.getBean("person"); person1.setTaxId(666); System.out.println(person2); R

STAT 440 - Spring 2019 - Midterm Project

STAT 440 - Spring 2019 - Midterm ProjectRecall that you may use your notes, books, or even the internet to help answer these questions, but all of thework should be your own and you should not ask anyone for help or about any details related to the c

On the way learning spring 4

Spring-19 Auto-Wiring  by type 在Xml文件中定义bean之间的关系时,有3种方法: 1. inner bean 2. 在bean 的property中定义另外一个bean 3. Spring Autowiring(有很多种类型, 这里 by type) <bean id="logger" class="com.caveofprogramming.spring.test.Logger" autowire="byType&

On the way learning spring 5

Spring-24 Adding Support for Annotation-Based Wiring Namespace-->check 'context'-->In 'context' Insert <context:annotation-config> element <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.spring

spring学习七 spring和dynamic project进行整合

spring和web项目进行整合,其实就是在项目启动时,就创建spring容器,然后在servlet中使用spring容器进行开. 注意:为了页面可以访问到servlet,因此servlet必须放进tomcat或者类似的服务器容器中,如果把servlet放进spring容器中,前端页面是无法访问的 第一步:导入spring-web.jar包,因为有一些别的依赖关系,还需要导入spring-tx.jar,spring-aop.jar等包 第二步:编写web.xml配置文件 在web.xml配置一个

On the way learning spring 3

Spring-12 Factory Beans and Methods static method in Class person non-static method in personFactory Spring-13 The P Namespace 注意Constructor 中的Arg 和建立的Bean之间的关系 p: tag 和 property tag 不要同时使用 Spring-14 Setting List Property In beans.xml file Insert con

deep learning for grasping的project的总结1

使用baxter来实现http://pr.cs.cornell.edu/deepgrasping/的项目: 首先谈谈参加NVIDIA举办的deep learning的讲座的一些心得体会.首先,深度学习产生是由于更多的数据集,更好的模型,以及很好的GPU处理能力.现在大型的神经网络大概是10层左右.其处理的信息应是随着神经网络的层数增加,其信息量是递减的,但是这里需要将主要的信息保留来存储与处理.深度学习如同火箭,而大型的神经网络就是发动机,数据就是燃料.对于HPU也就是many GPUs的称呼.

react-native init project 速度慢

这个问题和cocoapod更新慢,maven加载依赖慢是类似的,由于国内访问外网都不是很快,所以都是要指定代理,或者用国内镜像来解决此类问题. 不访问外网速度当然要快一些具体做法是修改npm的registry. 在终端输入npm --help 找到了很多命令,选择自己要用的config命令 发现npm是有很多命令的,当然我们要做的是配置npm 加载时从哪加载所以肯定是选择config命令了,具体配置什么 我是从stackoverflow上找的地址 https://github.com/faceb

On the way learning spring 6

Spring-47 Adding an Update Method to the DAO public boolean update(Offer offer){BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(offer); return jdbc.update("update offers set name=:name,text=:text,email=:email where id =:id&