SpringBoot源码 5.2.x 版本部署
GitHub代码仓库:github.com/spring-proj…
gradle下载地址:gradle.org/releases/
SpringBoot 5.2.x要对应gradle 5.6.3
gradle环境配置
一、解压gradle-5.6.3-all.zip文件
二、新建repo文件夹(用于存储依赖)
三、配置环境变量
添加进Path(版本的切换跟Path的前后顺序有关,排在最前面的是当前版本)
打开cmd测试是否配置成功
输入:gradle --version
配置gradle的国内镜像源
init.gradle没有的话可以创建
allprojects {
repositories {
mavenLocal()
maven { name "Alibaba" ; url "https://maven.aliyun.com/repository/public" }
maven { name "Bstek" ; url "http://nexus.bsdn.org/content/groups/public/" }
mavenCentral()
}
buildscript {
repositories {
maven { name "Alibaba" ; url 'https://maven.aliyun.com/repository/public' }
maven { name "Bstek" ; url 'http://nexus.bsdn.org/content/groups/public/' }
maven { name "M2" ; url 'https://plugins.gradle.org/m2/' }
}
}
}
自此基础环境已搭建完毕
IDEA项目环境配置
gradle配置
maven配置
kotlin配置
jdk配置
检查 ProjectSetting的jdk配置
如果此时下载依赖的速度还是很慢,补充以下代码
buildscript {
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/"}
maven { url "https://repo.spring.io/plugins-release" }
}
}
下载依赖
备注:这时候会 Background Build Tasks
可能碰到的依赖下载问题:
一、POM relocation to an other version number is not fully supported in Gradle : xml-apis:xml-apis:2.0.2
解决方案:修改引入方式,打开bulid.gradle文件,搜索configurations.all,添加如下内容:
force 'xml-apis:xml-apis:1.4.01'
新建module测试
https://start.aliyun.com/
新建测试接口
public interface MyTestService {
String sayHello(String name);
}
@Service
public class MyTestImpl implements MyTestService {
@Override
public String sayHello(String name) {
System.out.println(name);
return "success";
}
}
public class TestController {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean/config.xml");
MyTestService myTestService = (MyTestService) applicationContext.getBean("myTestService");
myTestService.sayHello("Spring框架!");
}
}
bean配置
<?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 id="myTestService" class="com.example.springmydemo.demos.service.impl.MyTestImpl"/>
</beans>
运行测试
备注:初次运行会下载依赖,观察依赖是否下载到了自己配置的maven地址,不是的话检查一下setting文件的仓库配置是否与IDEA的仓库配置一致
<localRepository>maven仓库地址</localRepository>