源码下载:https://u11556602.ctfile.com/fs/11556602-361219278java
https://download.csdn.net/download/qq_36267875/11089023web
1.建立maven项目spring
2.若是要想开发springboot程序只须要按照官方给出的要求配置一个父pom便可。apache
将下面的配置拷贝到pom中springboot
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> </parent>
就像下面这样 pomapp
<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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> </parent> <groupId>com.mldn</groupId> <artifactId>bootfirst</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>bootfirst</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
而后发现junit的版本显示黄色感叹号,这是由于,咱们引入了的parent里面规定了版本号,因此这里的版本号就能够去掉了maven
设置jdk版本spring-boot
在<properties>中设置版本号测试
<properties> <jdk.version>1.8</jdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
设置插件ui
<build> <finalName>bootfirst</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdk.version}</source><!-- 源代码使用的开发版本 --> <target>${jdk.version}</target><!-- 须要生成的目标class文件的编译版本 --> <encode>${project.build.sourceEncoding}</encode> </configuration> </plugin> </plugins> </build>
而后更新maven项目,发现版本变成了1.8
配置springboot依赖程序
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
以上pom文件的配置就完成了,完整的pom文件以下
<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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> </parent> <groupId>com.mldn</groupId> <artifactId>bootfirst</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>bootfirst</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.8</jdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <finalName>bootfirst</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdk.version}</source><!-- 源代码使用的开发版本 --> <target>${jdk.version}</target><!-- 须要生成的目标class文件的编译版本 --> <encode>${project.build.sourceEncoding}</encode> </configuration> </plugin> </plugins> </build> </project>
3.编写一个具体的程序
package com.mldn.bootfirst; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @EnableAutoConfiguration public class SampleController { @RequestMapping("/") @ResponseBody public String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); } }
而后能够直接经过java去运行该springboot程序。
在SampleController.java文件中,右键 Run as --java application
访问测试 http://localhost:8080/
若是如今是一个maven的普通项目,最简单的方法是在maven运行的时候输入:"spring-boot:run"
在项目上点击右键,run as -- maven build 选择第四个
开始下载插件,等插件下载完成以后,就能够执行了,就和编译打包是同样的
springboot的天生缺陷:是对开发者的要求比较高,必须会maven,ssm整合开发。