我特麼最煩的就是如今Java不知道抽什麼風,喜歡用maven這種,怎麼搞都會有錯誤提示的玩意。搞個spring boot,官方的所謂http://start.spring.io/生成的項目啓動不了。java
貓了個咪的,開發java,估計50%的時間在搞環境,最後發現兩篇好文章,總算把Spring Boot跑起來了。web
https://dzone.com/articles/spring-boot-a-quick-startspring
https://javabrains.io/courses/spring_bootquickstart/lessons/Creating-a-Spring-Boot-projectapache
這裏就不廢話了,直接一步入門。app
1. 首先在eclipse,新建一個maven項目,記得選擇:Create a simple project.less
而後那個狗日的maven就會一直跑啊跑,幾分鐘後,總算停下來了。eclipse
2. 修改pom。xml文件:maven
加入兩個配置:ide
<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>aaa</groupId> <artifactId>bbb</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
這裏ide會提示不少叉叉,項目跑不起來的時候,就開始處處懷疑這些叉叉是否是問題。其實,毫無關係。不用管他。spring-boot
3.添加個App和Controller:
package bbb; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; @SpringBootApplication public class App implements EmbeddedServletContainerCustomizer { public static void main(String[] args) { SpringApplication.run(App.class, args); } public void customize(ConfigurableEmbeddedServletContainer arg0) { arg0.setPort(8088); } }
package bbb; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloGbController { @GetMapping public String helloGb() { return "Gaurav Bytes says, \"Hello There!!!\""; } }
我這裏指定了端口,由於有衝突。最後啓動!!!
總算看到了有反應了。
媽的,一個下午就這樣沒了,各類垃圾的所謂入門教程。