Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wushizhenking
JavaGuide
提交
338662e4
J
JavaGuide
项目概览
wushizhenking
/
JavaGuide
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JavaGuide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
338662e4
编写于
9月 11, 2019
作者:
K
Kou Shuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update springboot-questions.md
上级
e3ad38a3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
3 deletion
+82
-3
docs/system-design/framework/spring/springboot-questions.md
docs/system-design/framework/spring/springboot-questions.md
+82
-3
未找到文件。
docs/system-design/framework/spring/springboot-questions.md
浏览文件 @
338662e4
...
...
@@ -20,12 +20,91 @@
7.
Spring Boot提供命令行接口(CLI)工具,用于开发和测试Spring Boot应用程序,如Java或Groovy。
8.
Spring Boot提供了多种插件,可以使用内置工具(如Maven和Gradle)开发和测试Spring Boot应用程序。
### 为什么需要Spring Boot?
###
3.
为什么需要Spring Boot?
Spring Framework旨在简化J2EE企业应用程序开发。Spring Boot Framework旨在简化Spring开发。
![
why-we-need-springboot
](
https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-7/why-we-need-springboot.png
)
### 什么是 Spring Boot Starters?
### 4. 什么是 Spring Boot Starters?
Spring Boot Starters 是一系列依赖关系的集合,因为它的存在,项目的依赖之间的关系对我们来说变的更加简单了。举个例子:在没有Spring Boot Starters之前,我们开发REST服务或Web应用程序时; 我们需要使用像Spring MVC,Tomcat和Jackson这样的库,这些依赖我们需要手动一个一个添加。但是,有了 Spring Boot Starters 我们只需要一个只需添加一个
**spring-boot-starter-web**
一个依赖就可以了,这个依赖包含的字依赖中包含了我们开发REST 服务需要的所有依赖。
```
xml
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
```
### 如何在Spring Boot应用程序中使用Jetty而不是Tomcat?
Spring Boot Web starter使用Tomcat作为默认的嵌入式servlet容器, 如果你想使用 Jetty 的话只需要修改pom.xml(Maven)或者build.gradle(Gradle)就可以了。
**Maven:**
```
xml
<!--从Web启动器依赖中排除Tomcat-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--添加Jetty依赖-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jetty
</artifactId>
</dependency>
```
**Gradle:**
```
groovy
compile
(
"org.springframework.boot:spring-boot-starter-web"
)
{
exclude
group:
'org.springframework.boot'
,
module:
'spring-boot-starter-tomcat'
}
compile
(
"org.springframework.boot:spring-boot-starter-jetty"
)
```
说个题外话,从上面可以看出使用 Gradle 更加简洁明了,但是国内目前还是 Maven 使用的多一点,我个人觉得 Gradle 在很多方面都要好很多。
### 介绍一下@SpringBootApplication注解
```
java
package
org.springframework.boot.autoconfigure
;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
CUSTOM
,
classes
=
TypeExcludeFilter
.
class
),
@Filter
(
type
=
FilterType
.
CUSTOM
,
classes
=
AutoConfigurationExcludeFilter
.
class
)
})
public
@interface
SpringBootApplication
{
......
}
```
```
java
package
org.springframework.boot
;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Configuration
public
@interface
SpringBootConfiguration
{
}
```
可以看出大概可以把
`@SpringBootApplication `
看作是
`@Configuration`
、
`@EnableAutoConfiguration`
、
`@ComponentScan `
注解的集合。根据 SpringBoot官网,这三个注解的作用分别是:
-
`@EnableAutoConfiguration`
:启用 SpringBoot 的自动配置机制
-
`@ComponentScan`
: 扫描被
`@Component`
(
`@Service`
,
`@Controller`
)注解的bean,注解默认会扫描该类所在的包下所有的类。
-
`@Configuration`
:允许在上下文中注册额外的bean或导入其他配置类
Spring Boot Starters 是一系列
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录