没有合适的资源?快使用搜索试试~ 我知道了~
Spring核心源码解析.pdf
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![chm](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![z01](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![z02](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/23500284/bg1.jpg)
1 Spring 框架核心源码
1、使用 Spring 框架
2、反射机制
IoC 控制反转 Inverse of Control 创建对象的权限,Java
程序中需要用到的对象不再由程序员自己创建,而是交
给 IoC 容器来创建。
1.1 IoC 核心思想
1、pom.xml
<dependencies>
<!-- 引入 Servlet 依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-
api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
<!-- 设置 Maven 的JDK版本,默认是5,需要手动改到8
-->
<build>
<plugins>
![](https://csdnimg.cn/release/download_crawler_static/23500284/bg2.jpg)
2、创建 Servlet
<plugin>
<groupId>org.apache.maven.plugins</groupId
>
<artifactId>maven-compiler-
plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
package com.southwind.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import java.io.IOException;
![](https://csdnimg.cn/release/download_crawler_static/23500284/bg3.jpg)
3、部署到 Tomcat
4、Servlet、Service、Dao
当需求发生变更的时候,可能需要频繁修改 Java 代码,
效率很低,如何解决?
静态工厂
@WebServlet("/hello")
public class HelloServlet extends
HttpServlet {
@Override
protected void doGet(HttpServletRequest
req, HttpServletResponse resp) throws
ServletException, IOException {
resp.getWriter().write("Spring");
}
}
package com.southwind.factory;
import com.southwind.dao.HelloDao;
import com.southwind.dao.impl.HelloDaoImpl;
public class BeanFactory {
public static HelloDao getDao(){
return new HelloDaoImpl();
}
}
![](https://csdnimg.cn/release/download_crawler_static/23500284/bg4.jpg)
上述的方式并不能解决我们的问题,需求发生改变的时
候,仍然需要修改代码,怎么做到
不改 Java 代码,就可以实现实现类的切换呢?
外部配置文件的方式
将具体的实现类写到配置文件中,Java 程序只需要读取
配置文件即可。
XML、YAML、Properties、JSON
1、定义外部配置文件
2、Java 程序读取这个配置文件
private HelloDao helloDao =
BeanFactory.getDao();
helloDao=com.southwind.dao.impl.HelloDaoImp
l
package com.southwind.factory;
import com.southwind.dao.HelloDao;
import com.southwind.dao.impl.HelloDaoImpl;
import
com.southwind.dao.impl.HelloDaoImpl2;
import java.io.IOException;
![](https://csdnimg.cn/release/download_crawler_static/23500284/bg5.jpg)
import
java.lang.reflect.InvocationTargetException
;
import java.util.Properties;
public class BeanFactory {
private static Properties properties;
static {
properties = new Properties();
try {
properties.load(BeanFactory.class.getClass
Loader().getResourceAsStream("factory.prope
rties"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static Object getDao(){
String value =
properties.getProperty("helloDao");
//反射机制创建对象
try {
Class clazz =
Class.forName(value);
剩余33页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/64cd4afe5d4a4a55b587f1fbc8434501_qq_25447799.jpg!1)
田野里的稻草人
- 粉丝: 49
- 资源: 8
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)