總是在傳統行業混,面試了幾家公司。我這種獨立開發者,(以前寫全棧,和麪試官爭吵了一下子啊,hah觀點不一樣,會java,數據庫,前端,android的簡直不被看好。主要是不太精通)面試劣勢。javascript
都是問一些集羣,併發,大數據,分佈式的東西,看來普通的java程序員混不下去了。hah。因此也學習一下吧~前端
在綜合考慮對spring也是比較熟悉的狀況下,想學習spring cloud,如今掀起對spring boot進行一些瞭解。java
spring boot就是一款spring「集團」整的一份輕量級,無配置,默認約定的快速開發框架。android
我如今學習的1.5.1.releasegit
建議使用maven進行項目管理,如今maven在java中用的應該是多的吧。maven3.2+程序員
<?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"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myproject</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
以上須要繼承spring boot parentweb
若是不想繼承,使用依賴管理面試
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
gradle也可,2.9+,build.gradle file:spring
plugins { id 'org.springframework.boot' version '1.5.1.RELEASE' id 'java' } jar { baseName = 'myproject' version = '0.0.1-SNAPSHOT' } repositories { jcenter() } dependencies { compile("org.springframework.boot:spring-boot-starter-web") testCompile("org.springframework.boot:spring-boot-starter-test") }
咱們新建一個類數據庫
package com.du; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration @ComponentScan public class Main { @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(Main.class, args); } }
run as java application,
而後打開localhost:8080便可看到Hello World!說明咱們的基礎配置已經成功
源碼可查看http://git.oschina.net/dim/SpringBoot
小技巧:在啓動後,你看到的是以下的內容
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: v1.5.1.RELEASE 2013-07-31 00:08:16.117 INFO 56603 --- [ main] o.s.b.s.app.SampleApplication
你能夠在你的classpath中假如一個文件banner.txt
隨便填寫,好比hellow dim!
而後就能夠看到
Hellow DIm! 2017-03-01 13:56:10.696 INFO 10332 --- [ main] com.du.Main : Starting Main on dim-PC with PID 10332 (C:\Users\Administrator\git\SpringBoot\target\classes started by Administrator in C:\Users\Administrator\git\SpringBoot)
定製本身的啓動廣告,hahah