1.jdk安装完成
2.maven配置成功
3.myeclipse的maven插件配置成功
1.mac Sierra 10.12.4
2.myeclipse2015
3.java版本:jdk 1.8.0_111
4.maven版本:Apache Maven 3.5.0
5.时间:2017-04-17
1.创建项目
1.1 选择maven项目
1.2创建第二步(不用修改)
1.3 选择创建类型
1.4填写项目信息(artifact id 项目名,group id 项目坐标)
2.第一个程序
2.1 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hdc.demo</groupId>
<artifactId>springBoot</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springBoot Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplicationpublic class GirlApplication {
public static void main(String[] args) {SpringApplication.run(GirlApplication.class, args);}}
在src/main/java下建立HelloController,内容如下
package com.hdc;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping(value="/hello",method=RequestMethod.GET)
public String say(){
return "Hello Spring Boot";
}
}
2.4 控制台显示如下内容,且没报错,说明运行成功. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.5.RELEASE)
2.5打开浏览器,访问http://localhost:8080/hello
1.** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
因为application.Java 文件不能直接放在main/java文件夹下,必须要建一个包把他放进去