1. 程式人生 > >像屎一樣的 Spring Boot入門,總算有反應了

像屎一樣的 Spring Boot入門,總算有反應了

zone context frame .org ret clas schema -1 eating

我特麽最煩的就是現在Java不知道抽什麽風,喜歡用maven這種,怎麽搞都會有錯誤提示的玩意。搞個spring boot,官方的所謂http://start.spring.io/生成的項目啟動不了。

貓了個咪的,開發java,估計50%的時間在搞環境,最後發現兩篇好文章,總算把Spring Boot跑起來了。

https://dzone.com/articles/spring-boot-a-quick-start

https://javabrains.io/courses/spring_bootquickstart/lessons/Creating-a-Spring-Boot-project

這裏就不廢話了,直接一步入門。

1. 首先在eclipse,新建一個maven項目,記得選擇:Create a simple project.

技術分享

然後那個狗日的maven就會一直跑啊跑,幾分鐘後,總算停下來了。

2. 修改pom。xml文件:

技術分享

加入兩個配置:

<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會提示很多叉叉,項目跑不起來的時候,就開始到處懷疑這些叉叉是不是問題。其實,毫無關系。不用管他。

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!!!\"";
    }
}

我這裏指定了端口,因為有沖突。最後啟動!!!

技術分享

總算看到了有反應了。

技術分享

媽的,一個下午就這樣沒了,各種垃圾的所謂入門教程。

  

像屎一樣的 Spring Boot入門,總算有反應了