Intellij和SpringBoot,gradle构建Hello world!工程

参考

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

都会显示相应的版本信息。






评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值