什么是SpringBoot?

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。

特征

  • 创建独立的Spring应用程序

  • 直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)

  • 提供固定的“入门”依赖项以简化构建配置

  • 尽可能自动配置Spring和第三方库

  • 提供生产就绪功能,例如指标,运行状况检查和外部化配置

  • 绝对没有代码生成,也不需要XML配置

 快速入门

(1)新建空项目New Project

==》命名项目名称,并选择要保存的目录

剩余步骤默认不用更改,直接ok即可。到此空白项目创建完成。

接下来在空白项目上建立模块(module)

(2)创建模块

==》创建modules --> Maven --> 选择SDK --> Create from archetype --> org.apache.maven.archetypes

==>命名GroupId,ArtifactId

==》配置仓库

==》命名模块名字,最终完成模块的创建

注:创建时,屏幕右下角提示如下,选择Enable Auto-Import即可

到此。模块创建完成

(3)配置项目配置文件(pom.xml)

 <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

(4)提供应用程序入口

 package com.demo.boot;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext; /**
* Hello world!
*/
@SpringBootApplication
public class App {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
}
}

(5)类的管理调用

==》pom.xml文件 添加类的依赖 spring-context和pring-boot-starter-web

    <dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.7.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

==》创建类User.java

 package com.demo.boot;

 import org.springframework.stereotype.Component;

 /**
* 使用@Component管理类
*/
@Component//别名 -->默认为类名首字母小写
public class User { @Override
public String toString() {
return "com.demo.boot.User:" + super.toString();
}
}

==>创建UserConfig类

 package com.demo.boot;

 import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean; /**
* 通过@Configuration注解把User类交给Spring容器管理
*/
@SpringBootConfiguration
public class UserConfig {
@Bean("createUser")默认别名,是方法名称
public User createUser() {
return new User();
}
}

==》应用程序入口

 package com.demo.boot;

 import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; /**
* Hello world!
*/
@SpringBootApplication//@SpringBootApplication=@Configuration+@ComponentScan+@EnableAutoConfiguration
public class App {
public static void main(String[] args) {
//ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("com.demo.boot");
User user = context.getBean("user", User.class);//别名为类名首字母小写
User user1 = context.getBean("createUser", User.class);//类别名为方法名
UserConfig userConfig = context.getBean(UserConfig.class);//类别名为方法名
System.out.print(user + "," + user1 + "," + userConfig);//实际通过springCGLIB代理类动态调用自定义方法(createUser)创建类实例
//输出:com.demo.boot.User:com.demo.boot.User@4c15e7fd,com.demo.boot.User:com.demo.boot.User@23986957,com.demo.boot.UserConfig$$EnhancerBySpringCGLIB$$72899f9e@23f7d05d
//context.close();
}
}

SpringBoot框架(1)--入门篇的更多相关文章

  1. Google C++测试框架系列入门篇:第三章 基本概念

    上一篇:Google C++测试框架系列入门篇:第二章 开始一个新项目 原始链接:Basic Concepts 词汇表 版本号:v_0.1 基本概念 使用GTest你肯定会接触到断言这个概念.断言是用 ...

  2. Google C++测试框架系列入门篇:第二章 开始一个新项目

    上一篇:Google C++测试框架系列入门篇:第一章 介绍:为什么使用GTest? 原始链接:Setting up a New Test Project 词汇表 版本号:v_0.1 开始一个新项目 ...

  3. 如何在Visual Studio 2017中使用C# 7+语法 构建NetCore应用框架之实战篇(二):BitAdminCore框架定位及架构 构建NetCore应用框架之实战篇系列 构建NetCore应用框架之实战篇(一):什么是框架,如何设计一个框架 NetCore入门篇:(十二)在IIS中部署Net Core程序

    如何在Visual Studio 2017中使用C# 7+语法   前言 之前不知看过哪位前辈的博文有点印象C# 7控制台开始支持执行异步方法,然后闲来无事,搞着,搞着没搞出来,然后就写了这篇博文,不 ...

  4. Springboot(一):入门篇

    什么是spring boot spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...

  5. 高性能NIO框架Netty入门篇

    http://cxytiandi.com/blog/detail/17345 Netty介绍 Netty是由JBOSS提供的一个java开源框架.Netty提供异步的.事件驱动的网络应用程序框架和工具 ...

  6. Google C++测试框架系列入门篇:第一章 介绍:为什么使用GTest?

    原始链接:Introduction: Why Google C++ Testing Framework? 词汇表 版本号:v_0.1 介绍:为什么使用GTest? GTest帮助你写更好的C++测试代 ...

  7. spring boot入门篇

    Spring Boot[快速入门]   Spring Boot 概述 Build Anything with Spring Boot:Spring Boot is the starting point ...

  8. SpringBoot 第一篇:入门篇

    作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10819728.html 版权声明:本文为博主原创文章,转载请附上博文链接! 前言   博主从去年 ...

  9. Springboot快速入门篇,图文并茂

    Springboot快速入门篇,图文并茂 文章已托管到GitHub,大家可以去GitHub查看阅读,欢迎老板们前来Star!搜索关注微信公众号 [码出Offer] 领取各种学习资料! image-20 ...

随机推荐

  1. python - 代码调试的好帮手sys._getframe()

    python 的调试,令人非常忧伤,通过将输出路径打印的方式,可以提高很大的方便性: import sys #coding=utf-8 def get_cur_info(): print sys._g ...

  2. 【web前端】面题整理(2)

    今天是520,单身狗在这里祝各位520快乐! DOM节点统计 DOM 的体积过大会影响页面性能,假如你想在用户关闭页面时统计(计算并反馈给服务器)当前页面中元素节点的数量总和.元素节点的最大嵌套深度以 ...

  3. Python2.7安装&配置环境变量

    python安装版本为2.7 下载安装包,双击安装,一路按照提示进行. 安装完成后,配置环境变量. 我的电脑—属性--高级系统设置—高级—环境变量--Path--编辑(将安装路径粘贴进去),添加到安装 ...

  4. python接口自动化:绕过验证码登录

    上线产品的登录接口会有验证码,一般可以通过添加cookie的方式绕过验证码. 一.抓登录的cookie 1. 先手动登录一次,然后用fiddler抓取这个cookie,再直接把这个值添加到cookie ...

  5. 【MM系列】SAP MM模块-控制采购订单中某些项目的输出显示

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-控制采购订单中某些 ...

  6. cocos2dx基础篇(17) 音乐音效SimpleAudioEngine

    [3.x]     (1)获取单例:sharedEngine() 改为 getInstance()     (2)实现了:音量的调节.     (3)修改了播放音效 playEffect() 的参数: ...

  7. cocos2dx基础篇(8) 开关按钮CCControlSwitch

    [3.x] (1)去掉 “CC” (2)对象类 CCObject 改为 Ref (3)标签类 LabelTTF 改为 Label (4)CCControlEvent 改为强枚举 Control::Ev ...

  8. Scratch少儿编程系列:(六)诗词《从军行》赏析

    一.程序说明 本程序用来显示<从军行>诗词,逐字显示.本来计划用2.0制作,但在制作过程中,在“造型”中无法输入汉字,临时采用3.0版本,1.4版本也可以. 二.程序流程图 为了更直观的描 ...

  9. Discrete Mathematics and Its Applications | 1 CHAPTER The Foundations: Logic and Proofs | 1.4 Predicates and Quantifiers

    The statements that describe valid input are known as preconditions and the conditions that the outp ...

  10. oracle表名中带@什么意思

    例如:select * from dim.dim_area_no@to_dw @后是实例名或数据源,一个简单例子,服务器上创建了2个数据库实例,名称分别为HR.BOSS, 如果你用PL/SQL DEV ...