Intellij和SpringBoot,gradle构建Hello world!工程
2016-08-22 17:57
721 查看
参考
https://spring.io/guides/gs/spring-boot/
首先下载Intellij,然后
(1)新建一个工程:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
@SpringBootApplication
public class DaoTestApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(DaoTestApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
package com.example;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello world!";
}
}
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'daotest'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
testCompile("junit:junit")
testCompile('org.springframework.boot:spring-boot-starter-test')
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
编译运行:
注意:需要设置JDK8,这个地方我设置少了,卡了蛮久的。
Java JDK 8 在 Windows 8.1下的安装以及环境变量的配置
在Windows 中,双击安装就是。
Win8.1下JDK8环境变量的配置:
依次单击计算机(Computer),选择属性(Properties),选择高级系统设置(Advanced systems settings), 选择环境变量(Environment Variables).
新建3个环境变量(PATH,CLASSPATH, JAVA_HOME),若有则不用新建。
给3个环境变量增加相应的值(由Java所在的路径决定,根据具体情况修改),例如:
PATH
D:\Program Files\Java\jdk1.8.0\bin; D:\Program Files\Java\jdk1.8.0\jre\bin
CLASSPATH D:\Program
Files\Java\jdk1.8.0\lib; D:\Program Files\Java\jdk1.8.0\lib\tools.jar
JAVA_HOME D:\Program Files\Java\jdk1.8.0
不同路径之间用分号隔开。
若添加正确,注销或重启计算机以后,在PowerShell或cmd中输入:
java -version
javac -version
都会显示相应的版本信息。
https://spring.io/guides/gs/spring-boot/
首先下载Intellij,然后
(1)新建一个工程:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
@SpringBootApplication
public class DaoTestApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(DaoTestApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
package com.example;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello world!";
}
}
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'daotest'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
testCompile("junit:junit")
testCompile('org.springframework.boot:spring-boot-starter-test')
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
编译运行:
注意:需要设置JDK8,这个地方我设置少了,卡了蛮久的。
Java JDK 8 在 Windows 8.1下的安装以及环境变量的配置
在Windows 中,双击安装就是。
Win8.1下JDK8环境变量的配置:
依次单击计算机(Computer),选择属性(Properties),选择高级系统设置(Advanced systems settings), 选择环境变量(Environment Variables).
新建3个环境变量(PATH,CLASSPATH, JAVA_HOME),若有则不用新建。
给3个环境变量增加相应的值(由Java所在的路径决定,根据具体情况修改),例如:
PATH
D:\Program Files\Java\jdk1.8.0\bin; D:\Program Files\Java\jdk1.8.0\jre\bin
CLASSPATH D:\Program
Files\Java\jdk1.8.0\lib; D:\Program Files\Java\jdk1.8.0\lib\tools.jar
JAVA_HOME D:\Program Files\Java\jdk1.8.0
不同路径之间用分号隔开。
若添加正确,注销或重启计算机以后,在PowerShell或cmd中输入:
java -version
javac -version
都会显示相应的版本信息。
相关文章推荐
- 使用Gradle构建SpringBoot工程系列:第五篇:编写Spring Boot主类及第一次运行
- 使用Gradle构建SpringBoot工程系列:第二篇:开发环境准备
- 使用Gradle构建SpringBoot工程系列:第六篇:SpringBoot 替换Tomcat为Jetty或UnderTow
- 使用Gradle构建SpringBoot工程系列:第一篇:Gradle及SpringBoot简介
- 使用Gradle构建SpringBoot工程系列:第一篇:Gradle及SpringBoot简介
- 使用Gradle构建SpringBoot工程系列:第二篇:开发环境准备
- 使用gradle构建springboot工程的以及部署springboot到linux服务
- 使用Gradle构建SpringBoot工程系列:第四篇:项目初始化(编辑build.gradle文件,引入项目基本配置及依赖)
- 使用Gradle构建SpringBoot工程系列:第三篇 创建Spring Boot项目
- 使用Gradle构建SpringBoot工程系列:第七篇:使用spring-boot-devtools开启热部署
- 【Spring】Spring-boot搭建一个简单的Hello World工程
- SpringBoot非官方教程 | 第一篇:构建第一个SpringBoot工程
- Gradle+Spring Boot+Git+Docker构建web服务
- 用Gradle构建Spring Boot项目
- Spring Boot + Gradle + Websocket 构建推送服务
- 用_Docker、Gradle_来构建、运行、发布一个_Spring_Boot_应用