zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Spring Boot(一):初步认识详解编程语言

SpringBoot编程语言 详解 认识 初步
2023-06-13 09:20:45 时间

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

1. 创建独立的Spring应用程序
 ?xml version="1.0" encoding="UTF-8"? 

 project xmlns="http://maven.apache.org/POM/4.0.0" 

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 

 parent 

 groupId org.springframework.boot /groupId 

 artifactId spring-boot-starter-parent /artifactId 

 version 1.4.1.RELEASE /version 

 /parent 

 modelVersion 4.0.0 /modelVersion 

 artifactId springboot-1 /artifactId 


groupId org.springframework.boot /groupId artifactId spring-boot-starter-web /artifactId /dependency /dependencies build plugins plugin groupId org.springframework.boot /groupId artifactId spring-boot-maven-plugin /artifactId version 1.4.1.RELEASE /version /plugin /plugins /build /project

这块统一用spring-boot-starter-parent做为parent 所以spring-boot-starter-web不用填写版本号

 parent 

 groupId org.springframework.boot /groupId 

 artifactId spring-boot-starter-parent /artifactId 

 version 1.4.1.RELEASE /version 

 /parent 

下面这个插件是用来运行Springboot的,通常有两种方式可以运行SpringBoot,一种是通过直接运行main方法,另外一种是通过使用下面的插件运行。 
两种方式有差别,一旦项目中需要访问资源的时候就需要通过插件运行,否则无法访问到资源

 plugin 

 groupId org.springframework.boot /groupId 

 artifactId spring-boot-maven-plugin /artifactId 

 version 1.4.1.RELEASE /version 

 /plugin 

上面是maven配置,接下来需要配置整个程序的入口,AppApplication

@SpringBootApplication 

public class AppApplication { 

 public static void main(String[] args) throws Exception { 

 SpringApplication.run(AppApplication.class, args); 

}

下面写了一个简易的controller,只要运行main方法或者插件,就能够正常访问了。这块需要注意,controller跟AppApplication放在一个包下面, 
如果不再一个下面需要配置扫描的包

@RestController 

public class IndexController { 

 @GetMapping("/index") 

 public ResponseEntity helloWord() { 

 return ResponseEntity.ok("hello word"); 

}

 



 

15710.html

cjavaxml