Maven,Gradle分别建立Spring-boot的demo工程
2017-06-29 11:42
405 查看
1、Maven建立spring-boot工程
2、创建mvn项目
3、在pom.xml文件中添加spring-boot包依赖
整体代码如下:
4、在Java文件中修改App.java
5、启动项目
6、gra
4000
dle构建spring-boot项目
安装好gradle环境之后,在项目目录下面填写gradle配置文件build.gradle
之后填写App.java文件,然后运行
Maven虽然没有官方的Wrapper,但是有一个第三方的Wrapper可以使用。 命令如下:`mvn -N io.takari:maven:wrapper`
2、创建mvn项目
mvn archetype:generate 自动化生成项目
3、在pom.xml文件中添加spring-boot包依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
整体代码如下:
<?xml version="1.0" encoding="UTF-8"?> <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>hello</groupId> <artifactId>world</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>world</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
4、在Java文件中修改App.java
package HelloWorld; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; /** * Hello world! * */ @SpringBootApplication @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); } }
5、启动项目
./mvnw spring-boot:run OR mvn spring-boot:run ./mvnw 是一个maven版本的第三方管理工具,类似于gradel的gradlew
6、gra
4000
dle构建spring-boot项目
安装好gradle环境之后,在项目目录下面填写gradle配置文件build.gradle
buildscript { ext { springBootVersion = '1.5.4.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile('org.springframework.boot:spring-boot-starter-web') testCompile('org.springframework.boot:spring-boot-starter-test') }
之后填写App.java文件,然后运行
./gradlew bootRun
相关文章推荐
- Intellij和SpringBoot,gradle构建Hello world!工程
- [置顶] 【微框架实战】Maven+SpringBoot 短信接口详解与Demo
- 使用Gradle构建SpringBoot工程系列:第四篇:项目初始化(编辑build.gradle文件,引入项目基本配置及依赖)
- 使用Gradle构建SpringBoot工程系列:第一篇:Gradle及SpringBoot简介
- eclipse+maven+springboot小Demo
- Spring Boot+Maven 工程配置h2内存数据库
- 使用Gradle构建SpringBoot工程系列:第五篇:编写Spring Boot主类及第一次运行
- 使用Gradle构建SpringBoot工程系列:第二篇:开发环境准备
- Springboot分模块开发详解(2):建立子工程
- gradle+maven+springboot实战
- Spring Boot+Maven 工程配置H2内存数据库
- 在sts中springboot工程的maven解析异常处理
- 使用Gradle构建SpringBoot工程系列:第六篇:SpringBoot 替换Tomcat为Jetty或UnderTow
- SpringBoot + Maven之Demo
- Maven构建springBoot Demo案例
- 用Eclipse将Springboot的maven工程打成jar包
- maven项目 spring-boot 整合 mybatis 实现查询功能demo
- Springboot分模块开发详解(1):建立父工程
- gradle+maven+springboot实战