魏名华

不要偷懒,做更好的自己

Nothing


No Welcome Message

玩转Spring全家桶--第一章:初识Spring (4讲)

Spring Initializr

https://start.spring.io/

应该还有命令行工具 CLI 吧,找找看?

  • Artifact
这个有点不好解释,大致说就是一个项目将要产生的文件,可以是jar文件,源文件,二进制文件,war文件,甚至是pom文件。每个artifact都由groupId:artifactId:version组成的标识符唯一识别。需要被使用(依赖)的artifact都要放在仓库(见Repository)中
  • Actuator
Spring Boot Actuator可以帮助你监控和管理Spring Boot应用,比如健康检查、审计、统计和HTTP追踪等。所有的这些特性可以通过JMX或者HTTP endpoints来获得。

hello world

@SpringBootApplication
@RestController
public class HelloworldApplication {

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

	@RequestMapping("/hello")
	public String hello() {
		return "Hello World!";
	}
}

注意2个注解的位置:@RestController、@RequestMapping(“/hello”)

运行结果

curl http://localhost:8080/hello         
Hello World!                                                         
curl http://localhost:8080/actuator/health
{"status":"UP"}   

pom

  • 打包

mvn clean package -Dmaven.test.skip

打包后target有2个jar包:hello-spring-0.0.1-SNAPSHOT.jar、hello-spring-0.0.1-SNAPSHOT.jar.original

原始包只有3k,完整包有17M,因为这个包括了所有的依赖,可以直接运行,运行jar包:java -jar hello-spring-0.0.1-SNAPSHOT.jar

  • parent

不指定parent,或使用自己的parent,可以加上dependencyManagement,来引入spring boot