Spring Boot ——002

1. 特点

建立独立的Spring应用程序
直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)
简化构建配置
尽可能自动配置Spring和3rd Party库
提供可用于生产的功能,例如指标,运行状况检查和外部化配置
完全没有代码生成,也不需要XML配置

2. 启动准备
  • 编程工具
    Popular(流行的) choices(选择) include IntelliJ IDEA, Spring Tools, Visual Studio Code, or Eclipse, and many more(等等).
  • jdk 版本
    We recommend AdoptOpenJDK version 8 or version 11.
3. start hello world
Step 1: Start a new Spring Boot project

Use start.spring.io to create a “web” project. In the “Dependencies” dialog search for and add the “web” dependency as shown in the screenshot(截图). Hit the “Generate” button, download the zip, and unpack(解压) it into a folder on your computer.
springIO网站新建项目,选择最新的版本,添加spring web依赖

  • 解决问题
    IDEA project模式下,不显示项目工程目录,只有几个配置文件
    配置文件*.iml 出错了
    方法1:找到 出错位置,修复
    方法2:清除配置,重新导入
    1)关闭IDEA,
    2)删除项目文件夹下的.idea文件夹
    3)重新用IDEA工具打开项目

    实际:未配置maven,maven配置国内仓库。依赖项目导入后正常显示。
  • 国内仓库
	   <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror> 
  • 这样配置 公司内部可以方便打包分享
  <localRepository>F:\MAVEN\apache-maven-3.3.9\conf\settings.xml\..\..\..\repository</localRepository>
  • 依赖导入失败
    检查maven 配置,仓库是否能访问。官网下载案例不会存在其它问题。
Step 2: Add your code

Open up the project in your IDE and locate the DemoApplication.java file in the src/main/java/com/example/demo folder. Now change the contents of the file by adding the extra method and annotations shown in the code below. You can copy and paste the code or just type it.
找到 启动类 DemoApplication 这里是 CrookLipsApplication。

新建controller ,放在和DemoApplication 同目录或子目录,
@SpringBootApplication 默认扫描当前类的同包以及子包下的类

``
`java

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

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

##### 3. step3 run
mvnw spring-boot:run  启动有点慢 
可以直接运行main

##### 4. end
You’ve already seen how simple Spring can be, but it’s also very flexible(灵活). There are thousands of things you can do with Spring, and we have lots of guides available to take you through the most popular choices. Why not keep on learning and try one of these additional guides?
鼓励你继续尝试。 大意:非常方便,灵活,你可以用spring做很多事,并且有很多技术文档帮助你做出最流行的选择





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值