1.maven安装配置好,使用eclipse创建maven项目(选择maven-archetype-quickstart)
2.然后进入http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/(maven installation)配置pom.xml文件
<!-- 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>
注释:eclipse创建maven项目时,自动加入了junit,我在创建时删除了junit模块依赖 与 test源码包
3.编写测试类
package hello; import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*; @Controller
@EnableAutoConfiguration
public class App{ @RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
} public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
}
4.最后进入项目根目录pom.xml文件下,执行mvn clean install
耐心等待maven构建完,运行App main方法,服务启动,成功。
启动后默认访问端口及地址是:http://127.0.0.1:8080
打包:
mvn clean install
会在项目target目录下生成jar执行文件
发布:
java -jar *-SNAPSHOT.jar
关注我的微信共享学习,讨论更多技术知识