MyEclipse配置Spring框架(基础篇)
一、新建项目,添加spring的相关jar包等
二、创建相关类以及属性和方法
Student.java
package com.yh;
public class Student implements People {
private Course course;
@Override
public void breath() {
// TODO Auto-generated method stub
System.out.println("呼吸");
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
}
三、配置xml文件
自动装配方法一:设置autowire(这里为byName)
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"> <bean id="student" class="com.yh.Student" autowire="byName"></bean> <bean id="course" class="com.yh.Course"></bean> </beans>
装配方法:Student类的成员变量名对应bean的id。
自动装配方法二:
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"> <bean id="student" class="com.yh.Student">
<property name="course" ref="course"></property>
</bean> <bean id="course" class="com.yh.Course"></bean> </beans>
装配方法:name对应Student类中名为course的成员变量,ref对应当前xml文件中id为course的bean。
四、编写测试类
package com.yh; import org.junit.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringDemoTest { @Test
public void demo01(){
String xmlPath="applicationContext.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(xmlPath);
Student stu = (Student)context.getBean("student");
stu.breath();
stu.getCourse().showCourse();
}
}
MyEclipse配置Spring框架(基础篇)的更多相关文章
- 白话Spring(基础篇)---AOP(execution表达式)
作为AOP的最后一节内容,我们来简单总结一下切面表达式上见的书写方法.下面的那内容有参考其他博文,在此先对开源博客的各位大神表示感谢! -------------------------------- ...
- 为MyEclipse配置Spring的约束
1.Spring框架概述 Spring是一个Service层的框架,可以整合许多其它框架进行工作 Spring的主要技术是 IOC(DI) AOP IOC - 控制反转(依赖注入) AOP - 免息那 ...
- Spring框架基础2
Spring框架基础2 测试Spring的AOP思想和注解的使用 导包(在前面的基础上添加) SpringAOP名词解释 AOP编程思想:横向重复代码,纵向抽取:就是说多个地方重复的代码可以抽取出来公 ...
- Spring学习指南-第二章-Spring框架基础(完)
第二章 Spring框架基础 面向接口编程的设计方法 在上一章中,我们看到了一个依赖于其他类的POJO类包含了对其依赖项的具体类的引用.例如,FixedDepositController 类包含 ...
- 白话Spring(基础篇)---AOP(execution表达式)(转)
[一知半解,就是给自己挖坑] 作为AOP的最后一节内容,我们来简单总结一下切面表达式上见的书写方法.下面的那内容有参考其他博文,在此先对开源博客的各位大神表示感谢! ----------------- ...
- 4-1 Spring框架基础知识
Spring框架基础知识 1.Spring 框架作用 主要解决了创建对象和管理对象的问题. 自动装配机制 2.Spring 框架 (Spring容器,JavaBean容器,Bean容器,Spring容 ...
- SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)
刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...
- Spring框架基础
1 Spring框架 1.1 Spring的基本概念 是一个轻量级的框架,提供基础的开发包,包括消息.web通讯.数据库.大数据.授权.手机应用.session管理 ...
- Spring 框架基础(04):AOP切面编程概念,几种实现方式演示
本文源码:GitHub·点这里 || GitEE·点这里 一.AOP基础简介 1.切面编程简介 AOP全称:Aspect Oriented Programming,面向切面编程.通过预编译方式和运行期 ...
随机推荐
- Python基础(__slots__)
class Point(object): __slots__ = ('name','point') p1 = Point() p1.name = 100 print(p1.name)#100 #p1. ...
- [bzoj5025]单调上升路径
由于题目的证明可以发现$ans\ge 2m/n \ge n-1$,于是大胆猜测答案就是n-1若n是奇数,则将边分为n组,每组(n-1)/2,如果同组内边没有交点,那么只需要每一组边一个权值区间,从每一 ...
- [bzoj1432]Function
对于这n个函数,构成了$n(n-1)/2$个交点,对交点离散后,相邻两个交点间函数的编号构成了一个排列,而每一个排列第i个数所构成的段数就是第i层的段数不妨设初始在-oo处这个排列是1,2,--,n, ...
- Java设计模式之(九)——门面模式
1.什么是门面模式? Provide a unified interface to a set of interfaces in a subsystem.Facade defines a higher ...
- MySQL数据库从入门到放弃(目录)
目录 MySQL数据库从入门到放弃 推荐阅读 MySQL数据库从入门到放弃 193 数据库基础 194 初识MySQL 195 Windows安装MySQL 196 Linux安装MySQL 197 ...
- 2017年最有前景的十大IT职业岗位
在IT行业,并不常存在失业的现象,因为目前整个行业存在严重的专业人才供给不足的现象:但同样,想要进入这个行业并牢牢站稳脚跟,你也需要拥有更强于其他行业的竞争力和承受更大的压力.那在行业中,哪些职位更有 ...
- DirectX12 3D 游戏开发与实战第八章内容(下)
DirectX12 3D 游戏开发与实战第八章内容(下) 8.9.材质的实现 下面是材质结构体的部分代码: // 简单的结构体来表示我们所演示的材料 struct Material { // 材质唯一 ...
- CMake 工程调用 Makefile 编译项目
本文主要介绍如何将一个依赖 Makefile 项目(MIDG)移植到 CMake 上. 首先介绍项目文件结构,文件主要由三个目录组成 3rdParty include src 其中,3rdParty ...
- 学习资源 Docker从入门到实践 pdf ,docker基础总结导图
学习资源 Docker从入门到实践 pdf ,docker基础总结导图 Docker从入门到实践 pdf 云盘地址:https://pan.baidu.com/s/1vYyxlW8SSFSsMuKaI ...
- Can't connect to HTTPS URL because the SSL module is not available. - skipping
今天用pip3安装第三方库的时候报了这样一个错: Can't connect to HTTPS URL because the SSL module is not available. - skipp ...