[SpringBoot系列001] SpringBoot介绍与功能

springboot特性

以jar包方式独立运行(jar -jar xxx.jar)
内嵌Servlet容器(tomcat, jetty),无需以war包形式部署到独立的servlet容器中
提供starter简化maven依赖包配置
自动装配bean(大多数场景)
零配置(理论上),Spring 4.x新特性,提倡使用java配置和注解配置结合而无需xml配置

官方向导搭建boot应用
http://start.spring.io/

Spring boot支持需要引入其提供的父POM

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
@EnableAutoConfiguration

@ComponentScan

@SpringBootApplication
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan

CI  持续集成    Spring boot 就是一个大管家

Spring boot热加载/部署

<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-devtools</artifactId>
</dependency>

Spring boot应用打包部署

<build>
	<plugins>
		<plugin><!-- 项目的打包发布 -->
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
			<mainClass>com.example.boot.SpringBootMain</mainClass>
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>repackage</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

修改端口

server.port=8888
java -jar xx.jar --server.port=8888
1.@EnableAutoConfiguration:开启自动配置功能,默认本包和子包
@ComponentScan(basePackages={"com.example.boot"}) 包扫描


2.@SpringBootApplication配置详解:
他是一个组合注解,他内部主要包含三个子注解:@SpringBootConfiguration、
@EnableAutoConfiguration、@ComponentScan

@SpringBootConfiguration:他继承@Configuration,说明这是一个配置类,什么是配
置类呢?就相当于我们以前写的xml配置,例如我们我们的bean标签,用来实例化一个bean。
那么在这个配置类中就是实现以前我们xml配置的功能

@EnableAutoConfiguration:开启自动配置功能,他会扫描带有@Configuration的类,
然后初始化这些配置类中的信息并且加入到应用上下文中去,同时完成一些基本的初始化工作

@ComponentScan:组件包扫描,也就是我现在需要扫描哪些包下面的注解,可自动发现和
装配一些bean。默认扫描当前启动类所在包下面的类和下面的所有子包
参数引用
application.properties
teacher.id=1
teacher.name=zhangsan
teacher.info=Teacher ${teacher.name}'s number is ${teacher.id}

随机内容生成
# 随机字符串
random.string=${random.value}
# 随机int
random.number=${random.int}
# 随机long
random.long=${random.long}
# 1-20的随机数
random.b=${random.int[1,20]}

环境配置
总结:
1.application.properties中配置通用内容,并设置spring.profiles.active=dev,
以开发环境为默认配置
2.application-{profile}.properties中配置各个环境不同的内容
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kwan的解忧杂货铺@新空间代码工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值