spring boot框架eclipse快速搭建


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.编写测试类

 1 package hello;
 2 
 3 import org.springframework.boot.*;
 4 import org.springframework.boot.autoconfigure.*;
 5 import org.springframework.stereotype.*;
 6 import org.springframework.web.bind.annotation.*;
 7 
 8 @Controller
 9 @EnableAutoConfiguration
10 public class App{
11 
12     @RequestMapping("/")
13     @ResponseBody
14     String home() {
15         return "Hello World!";
16     }
17 
18     public static void main(String[] args) throws Exception {
19         SpringApplication.run(App.class, args);
20     }
21 }

4.最后进入项目根目录pom.xml文件下,执行mvn clean install

耐心等待maven构建完,运行App main方法,服务启动,成功。

启动后默认访问端口及地址是:http://127.0.0.1:8080

 

打包:

mvn clean install

会在项目target目录下生成jar执行文件

 

发布:

java -jar *-SNAPSHOT.jar

 

关注我的微信共享学习,讨论更多技术知识


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM