1. 程式人生 > >Myeclipse建立spring boot

Myeclipse建立spring boot

1.maven匯入

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.3.0.RELEASE</version>
		<relativePath />
	</parent>
 <!-- 對web開發的支援,包括tomcat,spring-webmvc -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- spring boot核心,包括自動配置支援,日誌和YAML -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
		</dependency>
		<!-- DevTools in Spring Boot 專案熱部署 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>

2.在src/main/java下建立一個包在建立一個class,記得不要直接在src/main/java下建立這個class不然會報錯
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyFirstSpringBoot {

	public static void main(String[] args) {
		SpringApplication.run(MyFirstSpringBoot.class, args);
	}
}
這個用於啟動spring boot專案

3.在src/main/resources下建立

這個是spring boot 的配置檔案

4.會報錯

Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]

這是因為你maven匯入javax.service這個包與spring boot自帶的tomcat包衝突 把maven裡面這個包刪掉就行