1、在eclipse中安装Gradle插件
2、新建Gradle Project
方法一:直接新建
方法二:
1) 直接新建一个Dynamic Web Project
2) 右击项目—>Configure—>Convert to Gradle Prorject
3、转换项目之后,在src下如下目录,其中java放置源代码,resources放置配置文件,webapp放置视图资源和web.xml。
3、 在项目根目录下新建build.gradle,下载依赖包
1)build.gradle文件
apply plugin: 'java'
apply plugin: 'war' //用来生成war
apply plugin: 'eclipse-wtp' //用来生成Eclipseweb项目的插件(web-tool-platform)
version = '1.0' //property
// Uses JDK 7
sourceCompatibility = 1.7
targetCompatibility = 1.7
// 1. Get dependencies from Maven local repository
// 2. Get dependencies from Maven central repository
repositories {
mavenCentral()
}
//Project dependencies
dependencies {
compile 'org.apache.tomcat:tomcat-servlet-api:8.0.24'
compile 'jstl:jstl:1.2'
compile 'org.springframework:spring-beans:4.1.7.RELEASE'
compile 'org.springframework:spring-web:4.1.7.RELEASE'
compile 'org.springframework:spring-webmvc:4.1.7.RELEASE'
compile 'org.springframework:spring-tx:4.1.7.RELEASE'
compile 'com.alibaba:druid:1.0.15'
compile 'org.aspectj:aspectjweaver:1.8.6'
compile 'mysql:mysql-connector-java:5.1.36'
compile 'org.mybatis:mybatis-spring:1.2.3'
compile 'org.mybatis:mybatis:3.3.0'
compile 'org.springframework:spring-jdbc:4.1.7.RELEASE'
compile 'junit:junit:4.12'
compile 'org.springframework:spring-test:4.0.5.RELEASE'
//include in compile only, exclude in the war
providedCompile 'javax.servlet:servlet-api:2.5'
}
在build.gradle文件中配置我们项目需要依赖的包,这些我们使用的是maven仓库中的资源。关于这些jar包在哪里找的,这里推荐一个网站:
http://www.mvnrepository.com/
2)下载依赖包
右击项目—>Gradle—>Refresh Dependencies,等待依赖下载完成。
4、整合Spring-Mybatis
1)配置文件
spring-mybatis.xml配置文件