微网站在哪个平台上搭建好 知乎,网站开发 上海,生物科技公司网站模板,上海市政网一、Spring整体架构和环境搭建
1.1 Spring的整体架构
Spring框架是一个分层架构#xff0c;包含一系列功能要素#xff0c;被分为大约20个模块 Spring核心容器#xff1a;包含Core、Bean、Context、Expression Language模块 Core #xff1a;其他组件的基本核心#xff…一、Spring整体架构和环境搭建
1.1 Spring的整体架构
Spring框架是一个分层架构包含一系列功能要素被分为大约20个模块 Spring核心容器包含Core、Bean、Context、Expression Language模块 Core 其他组件的基本核心主要包含Spring框架基本的核心工具类Beans 包含访问配置文件、创建和管理bean以及IOC/DI控制反转和依赖注入操作相关的所有类Context 构建与Core和Beans基础之上继承BeanFactory提供上下文信息扩展出JNDI、EJB、电子邮件、国际化等功能Expression Language 提供了一个强大的语言表达式用于在运行时查询和操纵对象。 Spring数据访问与集成 JDBC 提供了JDBC的抽象层ORM 提供了JPA、JDO、Hibernate、iBatis 等ORM映射层OXM 提供了Object/XML映射实现的抽象层该实现包括JAXB、Castor、XMLBeans、JiBX和XStreamJMSJava Messaging Service 制造和消费消息Transaction 编程和声明性的事务管理 Spring AOP集成了所有AOP功能Spring Web与远程调用 Web 提供了基础的 Web 开发的上下文信息现有的Web框架如JSF、Tapestry、Structs等提供了集成Web MVC提供了 Web 应用的 Model-View-Controller 全功能实现。Websocket 1.2 Spring环境搭建
1.2.1 安装git Git - Downloads 1.2.2 安装Gradle 1.下载安装包 下载地址 Gradle Distributions 2配置环境变量 #1.打开.bash_profile文件
open -e ~/.bash_profile
#2.在.bash_profile文件中配置环境变量
GRADLE_HOME//Users/sunshine/Documents/software/gradle/gradle-7.5.1
export GRADLE_HOME
export PATH$PATH:$GRADLE_HOME/bin 3查看Gradle版本 gradle -version 1.2.3 下载Spring源码 git clone gitgithub.com:spring-projects/spring-framework.git
git clone https://github.com/spring-projects/spring-framework.git 我使用的是5.3.x分支。 注意要使用 gitgithub.com:spring-projects/spring-framework.git 需要配置ssh秘钥 ssh-keygen -t rsa -b 4096 -C your_emailexample.com
//会生成私钥文件 id_rsa 和公钥文件 id_rsa.pub
//windows 一般在 C:\Users\Administrator\.ssh 目录linux和mac在 ~/.ssh
//把生成的公钥拷贝到GitHub 的设置中的 SSH 密钥部分 如果使用 https 超时可以增加 Git 的 HTTP/HTTPS 超时时间 git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999 如果使用了VPN代理服务器确保 Git 的代理设置是正确的。你可以通过以下命令检查或设置代理 //查看当前代理设置
git config --global --get http.proxy
//设置代理
git config --global http.proxy http://proxy_host:port
git config --global https.proxy https://proxy_host:port
//取消代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy 1.2.4 配置IDEA 配置IDEA的本地gradle环境 配置项目字节码版本 最后在 Project Structure 配置sdk版本。 1.2.5 配置 Spring-Framework 源码的gradle仓库 配置gradle下载地址为本地路径为gradle二进制文件压缩包路径: //文件为 gradle/wrapper/gradle-wrapper.properties
distributionUrlfile:///F:/work_folder/gradle-7.5.1-bin.zip 配置仓库镜像 //根目录下文件\buildSrc\build.gradle
repositories {maven { url https://maven.aliyun.com/repository/public/ }maven { url https://maven.aliyun.com/repository/central }mavenCentral()gradlePluginPortal()
}根目录下文件\build.gradle 的 mavenCentral() 之前加上 maven { url https://maven.aliyun.com/repository/public/ }
maven { url https://maven.aliyun.com/repository/central }
maven { url https://maven.aliyun.com/repository/spring-plugin }
maven { url https://maven.aliyun.com/repository/gradle-plugin } 1.2.6 新建模块测试环境 添加依赖 /spring-f2-test/build.gradle 添加测试类 public class User {String name;public User(String name) {this.name name;}public String getName() {return name;}public void setName(String name) {this.name name;}Overridepublic String toString() {return User{ name name \ };}
}Configuration
public class JavaConfig {Beanpublic User user(){return new User(lister);}
}public class TestApplication {public static void main(String[] args) {AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext(JavaConfig.class);User user (User) context.getBean(user);System.out.println(user);}
}
//结果打印
User{namelister}