- 浏览: 404625 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (325)
- 数据中台 (15)
- 设计模式 (7)
- 数据结构 (4)
- JavaScript (51)
- 网页设计与制作 (7)
- Flex (4)
- Fckeditor (7)
- Struts (12)
- Spring (19)
- Hibernate (14)
- EJB3.0 (19)
- Java EE 6 (2)
- JSP (22)
- 辅助框架 (9)
- WebService (1)
- XML (8)
- 正则表达式 (5)
- 并发(多线程) (2)
- Java网络 (10)
- 开发工具 (25)
- Oracle (15)
- MySQL (8)
- Git (4)
- SQL Server (2)
- C# (9)
- php (14)
- asp (2)
- ColdFusion (5)
- Tex (1)
- 云游戏 (1)
最新评论
-
CSDNBenbenChong:
...
SQL里desc和asc是什么意思 -
雪狐一号:
非常好 顶一个
SQL里desc和asc是什么意思 -
boyleichinasoft:
thinking...
该如何去使用设计模式呢? -
nforce_com:
写的很好,学习了!不过Student 一般情况下不会删除所有 ...
JPA多对多 -
TaoistWar:
那是FCKEditor的,详细信息只能查看官方文档,或者直接看 ...
1.fckeditor-java-2.5给上传图片添加水印
1.Spring依赖库
* SPRING_HOME/dist/spring.jar
* SPRING_HOME/lib/jakarta-commons/commons-logging.jar
* SPRING_HOME/lib/log4j/log4j-1.2.14.jar
2.拷贝Spring的配置文件applicationContext.xml到src下
* SPRING_HOME/samples/jpetstore/war/WEB-INF/applicationContext.xml
3.在UserManager类中提供setter方法,让Spring将实例化发的实现注入给我们
4.让Spring管理我们的对象创建,让Spring管理我们的对象间的依赖关系,必需定义Spring配置文件
5.编写客户端
//通过配置文件初始化Bean工厂
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
//通过Bean工厂得到UserManager
UserManager userManager = (UserManager) factory.getBean("UserManager");
userManager.save("张三", "123");
Spring IoC的关键:
* 让Spring管理你的对象,必须将被管理的对象定义在配置文件中
* 定义setter或构造方法,Spring会将对象注入过来
=========================================================================
UserManager.java
package com.bjsxt.spring.manager;
import com.bjsxt.spring.dao.UserDao;
public class UserManager {
private UserDao userDao;
public UserManager(UserDao userDao) {
this.userDao = userDao;
}
// public void setUserDao(UserDao userDao) {
// this.userDao = userDao;
// }
public void delete(String userid) {
}
public void modify(String userid, String username, String password) {
}
public void save(String username, String password) {
userDao.save(username, password);
}
}
=========================================================================
UserDao.java
package com.bjsxt.spring.dao;
public interface UserDao {
public void delete(String userid);
public void modify(String userid, String username, String password);
public void save(String username, String password);
}
=========================================================================
UserDao4MySqlImpl.java
package com.bjsxt.spring.dao;
public class UserDao4MySqlImpl implements UserDao {
public void delete(String userid) {
}
public void modify(String userid, String username, String password) {
}
public void save(String username, String password) {
System.out.println("-----------UserDao4MySqlImpl.save-----------");
}
}
=========================================================================
UserDao4OracleImpl .java
package com.bjsxt.spring.dao;
public class UserDao4OracleImpl implements UserDao {
public void delete(String userid) {
}
public void modify(String userid, String username, String password) {
}
public void save(String username, String password) {
System.out.println("-----------UserDao4OracleImpl.save-----------");
}
}
=========================================================================
Client .java
package com.bjsxt.spring.client;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.bjsxt.spring.manager.UserManager;
public class Client {
public static void main(String[] args) {
//通过配置文件初始化Bean工厂
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
//通过Bean工厂得到UserManager
UserManager userManager = (UserManager) factory.getBean("UserManager");
userManager.save("张三", "123");
}
}
=========================================================================
applicationContext.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="UserDao4MySqlImpl" class="com.bjsxt.spring.dao.UserDao4MySqlImpl"></bean>
<bean id="UserDao4OracleImpl" class="com.bjsxt.spring.dao.UserDao4OracleImpl"></bean>
<bean id="UserManager" class="com.bjsxt.spring.manager.UserManager">
<!-- 构造方法注入 -->
<constructor-arg ref="UserDao4MySqlImpl"></constructor-arg>
<!-- setter注入
<property name="userDao" ref="UserDao4MySqlImpl"></property>
-->
</bean>
</beans>
- spring_beginning.rar (2.6 MB)
- 下载次数: 0
发表评论
-
Spring基于注解形式的AOP
2010-01-19 17:17 9291.定义切面、通知、切入点 接口: packa ... -
spring自定义属性编辑器
2010-01-18 13:13 777属性编辑器,是将spring配置文件中的字符串转换成 ... -
Acegi
2009-11-08 22:43 707http://www.springside.org.cn/do ... -
1.Spring环境的搭建
2009-09-29 08:32 11681.所需jar包 Spring jar(10): spr ... -
Struts2+ Spring + Hibernate + Dwr + JBPM整合
2009-08-21 13:20 1265一、配置web.xml <?xml version=& ... -
Spring的定时调度--Quartz
2009-06-03 17:40 2300Quartz是一个强大的企业级任务调度框架,Spri ... -
Spring2.5 + JPA(Hibernate)实现
2009-04-14 01:00 40911.JPA的实现框架 使用MyEclips ... -
关于spring声明式事务配置方法
2009-02-06 00:48 3056对于spring的声明式事务的配置的使用常用的 ... -
spring声明式事务配置方法(六):aop:config切入
2009-02-06 00:32 8174<?xml version="1.0" ... -
spring声明式事务配置方法(五):DefaultAdvisorAutoProxyCreator
2009-02-06 00:31 1075<?xml version="1.0" ... -
spring声明式事务配置方法(四):BeanNameAutoProxyCreator注入Bean
2009-02-06 00:28 3350<?xml version="1.0" ... -
spring声明式事务配置方法(三):TransactionProxyFactoryBean继承方式
2009-02-06 00:27 1234<?xml version="1.0" ... -
spring声明式事务配置方法(二):TransactionProxyFactoryBean方式
2009-02-06 00:25 1067<?xml version="1.0" ... -
spring声明式事务配置方法(-):TransactionProxyFactoryBean方式
2009-02-06 00:24 1426<?xml version="1.0" ... -
Spring如何在jsp页面中获取Bean!
2009-02-03 19:03 1949在这几天做一个类似asp的标签功能,用了以前JUn ... -
定时调度
2008-12-19 11:26 739<!-- 自动生成autoCreatesiteMap - ... -
3. spring_injection
2008-10-11 11:02 593Spring的普通属性注入 参见Spring文档3.3 ... -
1.spring_whyspring
2008-10-10 17:20 591Spring出现以前的软件开发状态。
相关推荐
20110930_spring_beginning20110930_spring_beginning20110930_spring_beginning20110930_spring_beginning20110930_spring_beginning20110930_spring_beginning
《 Beginning_Spring_Boot_2 》是一本专为初学者设计的...Spring_Boot_2_Tutorial.pdf这个文档很可能是本书的电子版,读者可以通过阅读其中的内容,逐步掌握Spring Boot 2的精髓,成为一名熟练的Spring Boot开发者。
内容如下: spring.rar [spring_aop1] [spring_aop2] [spring_aop3] [spring_aop4] [spring_autowire_byName] [spring_autowire_byType] [spring_beginning] [spring_hibernate_1] [spring_hibernate_2] ...
根据提供的文件信息,我们可以归纳出以下关于《Beginning Spring Boot 2》这本书的关键知识点: ### 一、书籍基本信息 - **书名**:Beginning Spring Boot 2: Applications and Microservices with the Spring ...
### 使用Spring进行依赖注入 (Chapter 2) 依赖注入(DI, Dependency Injection)是Spring框架的核心特性之一。本章详细讲解了如何在Spring框架中实现依赖注入,并探讨了不同的依赖注入方式:构造器注入、setter注入...
Beginning Spring Boot 2 Beginning Spring Boot 2 Beginning Spring Boot 2
Beginning.Spring-Spring入门经典.part1.rarBeginning.Spring-Spring入门经典.part1.rarBeginning.Spring-Spring入门经典.part1.rarBeginning.Spring-Spring入门经典.part1.rar
This book will help you understand what Spring Boot is, how Spring Boot helps you build Spring-based applications quickly and easily, and the inner workings of Spring Boot using easy-to-follow ...
Spring is the most popular Java-based framework for building enterprise applications. The Spring framework provides a rich ecosystem of projects to address modern application needs, like security, ...
Beginning Spring Boot 2 Applications and Microservices with the Spring Framework 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Beginning Spring Boot 2 - K. Siva Prasad Reddy. Learn Spring Boot and how to build Java-based enterprise, web, and microservice applications with it. In this book, you'll see how to work with ...
After reading and learning with Beginning Spring Boot 2, you'll have the skills and techniques to start building your first Spring Boot applications and microservices with confidence to take the next ...
Beginning Spring is the complete beginner's guide to Java's most popular framework. Written with an eye toward real-world enterprises, the book covers all aspects of application development within the...
Beginning with an introduction to Spring and setting up the environment, the book will teach you in detail about the Bean life cycle and help you discover the power of wiring for dependency injection....
Beginning Spring Boot 2.pdf Learn Microservices with Spring Boot.pdf Pro Spring 5, 5th Edition.pdf Pro Spring Boot 2, 2nd Edition.pdf Pro Spring Boot.pdf Spring 5 Recipes, 4th Edition.pdf Spring Boot ...
通过上述章节的详细介绍,《Beginning Spring》这本书为初学者提供了全面而深入的Spring框架学习指南,不仅覆盖了Spring的基本概念和技术细节,还提供了实用的案例研究和最佳实践建议,对于想要深入了解Spring框架的...