Spring5的一些变化
-
Spring5.x整个框架已经全面基于Java8及以上版本,所以Spring5最低JDK版本要求是8
-
由于Java8的反射增强,因此Spring5.x可以对方法的参数进行更高效的访问
-
Spring5.x核心接口已经加入了Java8接口支持的默认方法
-
Spring5.x已经自带了通用的日志封装,不需要再额外使用commons-loging.jar包
-
Spring5.x引入了@Nullable和@NotNull注解来修饰可空的参数及返回值,避免运行时的空指针异常
-
Spring5.x支持JetBrains Kotlin语言,而且新增了对函数式Bean定义的支持,包括函数式的Bean检索样式
-
取消了相关类、包和方法:
beans.factory.access
dbc.support.nativejdbc
从spring-aspects模块中移除了mock.staicmock包
不再提供AnnotationDrivenStaticEntityMockingControl支持
官网在解释Spring框架的常用场景的图:
Spring框架帮我们简化了什么开发工作:
-
查询数据:DAO+POJO的初始化和装载的过程被简化
-
给所有Service的查询方法记录日志
进入官网:https://spring.io/
-
点击Spring Framework
-
选择Learn
查看当前最新的GA版本(稳定版本)
GA:正式发布的稳定版本
PRE:预览版本,可能存在很多漏洞
SNAPSHOT:快照版本 -
点击GitHub头像
-
找到
Access to Binaries
选择Spring Framework Artifacts
-
进入Spring Framework Artifacts页面后,找到
Downloading a Distribution
,进入链接 -
进入后点击Artifacts,选择release
-
依次找如下路径release/org/springframework/spring/
-
点击URL to file的链接
-
选取最新版本
-
下载dist.zip
dist:源码包(包含了docs和scheme) docs:官方文档 scheme:配置文件
Spring5需要的主要的Jar包
spring-beans-5.3.9.jar
spring-core-5.3.9.jar
spring-expression-5.3.9.jar
spring-context-5.3.9.jar
注意事项:如果只是引入这几个包,还需要额外引入一个外部包commons-logging-1.2.jar
,Spring5.x版本需要导入spring-jcl-5.3.9.jar
测试代码
import com.carl.entity.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
/**
* @PackageName PACKAGE_NAME
* @Auther carl
* @Description: 测试
* @Version V1.0
* @Date 2022-09-24 11:08
* Modified By:chihuaxin
**/
public class Main {
@Test
public void testUser(){
ApplicationContext context=new ClassPathXmlApplicationContext("bean1.xml");
// ApplicationContext context = new FileSystemXmlApplicationContext("E:\\project\\studyProject\\JavaEE\\Spring\\introduction\\Demo1\\resource\\bean1.xml");
// //FileSystemXmlApplicationContext()默认是在当前项目下(E:\project\studyProject\JavaEE\Spring\introduction\Demo1)
// ApplicationContext context = new FileSystemXmlApplicationContext("resource\\bean1.xml");
User user = context.getBean("user", User.class);
System.out.println(user);
}
}
<?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="user" class="com.carl.entity.User"/>
</beans>
标签:基本,Spring,版本,spring,jar,context,使用,Spring5
From: https://blog.csdn.net/qq_39052339/article/details/139660886