使用ctrl+N能查找类
在接口内部使用Ctr+H能查找实现类
ctrl + F12能查看类有啥方法
1 环境搭建
为了保持一致,Spring使用的版本是5.0.x,gradle使用的版本是4.4.1,JDK使用的版本是1.8(JDK8),IDEA使用的版本是2021.3。
1.1 Gradle安装
GRADLE_HOME,PATH,GRADLE_USER_HOME
maven本地仓库->所有的jar包,同理,gradle也有本地仓库,在gradle安装目录中新建gradle目录作为仓库:
配置下载阿里云镜像:
在gradle安装目录的init.d文件夹中新建init.gradle文件,并添加如下内容:
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
maven {
url NEXUS_URL
}
}
}
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
maven {
url NEXUS_URL
}
}
}
}
1.2 下载并打开项目
打开项目(本项目使用的版本是5.0.x):
配置Gradle以及JDK:
如果速度慢,可以取消自动的下载,直接进行index
1.3 可能出现的问题:
1.No such property: values forclass:org.gradle.api.internal.tasks.DefaultTaskDependency Possible solutions: values
打开文件,并注释:
1.4 测试是否配置好环境
新建包 :
配置build.gradle
plugins {
id 'java'
}
group 'org.springframework'
version '5.0.21.BUILD-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.12'
compile(project(":spring-context"))
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'
}
新建pojo.Person
package com.CodingInn.pojo;
import lombok.Data;
@Data
public class Person {
private String name;
}
新建beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="com.CodingInn.pojo.Person" id="person">
<property name="name" value="zhangsan"/>
</bean>
</beans>
测试
package com.CodingInn;
import com.CodingInn.pojo.Person;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class test {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Person bean = context.getBean(Person.class);
System.out.println(bean);
}
}
|