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,面向切面编程.通过预编译方式和运行期 ...
随机推荐
- 【数据结构&算法】12-线索二叉树
目录 前言 线索二叉树的概念 线索二叉树的实现 线索二叉树的寻点思路二 类双向链表参考图 参考代码 中序遍历线索化 前言 在<大话数据结构>P190 页中有一句话:其实线索二叉树,就等于是 ...
- Windows操作系统安全加固基线检测脚本
一.背景信息 在我们的安全运维工作中经常需要进行安全基线配置和检查,所谓的安全基线配置就是系统的最基础的安全配置,安全基线检查涉及操作系统.中间件.数据库.甚至是交换机等网络基础设备的检查,面对如此繁 ...
- docker 启动报错:Docker.Core.Backend.BackendException: Error response from daemon: open \\.\pipe\docker_e
win10 docker启动后报错: Docker.Core.Backend.BackendException:Error response from daemon: open \\.\pipe\do ...
- 洛谷 P4900 - 食堂(推式子)
洛谷题面传送门 首先推式子: \[\begin{aligned} ans&=\sum\limits_{i=A}^B\sum\limits_{j=1}^i\{\dfrac{i}{j}\} \en ...
- 3D-DNA 挂载染色体
3D-DNA是一款简单,方便的处理Hi-C软件,可将contig提升到染色体水平.其githup网址:https://github.com/theaidenlab/3d-dna 3D-DNA流程简介 ...
- MYSQL5.8---1
主键不能为空,唯一键可以为空且可以多个唯一键 外键必须为另一个表中的主键 外键的用途是确保数据的完整性.它通常包括以下几种: 1 实体完整性,确保每个实体是唯一的(通过主键来实施) 2 域完整性,确保 ...
- 毕业设计之LVS+keealive 负载均衡高可用实现
环境介绍 centos6.9最小化安装 主机名 IPADDR lvsA.load.quan.bbs 192.168.111.131 lvsB.load.quan.bbs 192.168.111.132 ...
- python爬虫之正则表达式(用在其他地方也可)
1. 常用的匹配规则 ### 常用的匹配规则 # \w 匹配字母.数字及下划线 # \W 匹配不是字母.数字及下划线的字符 # \s 匹配任意空白字符,等价于[\t\n\t\f] # \S 匹配任意非 ...
- 使用Mybatis出现的问题+配置优化+ResultMap
一.可能出现的问题 1.Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: ...
- 分布式事务(4)---最终一致性方案之TCC
分布式事务(1)-理论基础 分布式事务(2)---强一致性分布式事务解决方案 分布式事务(3)---强一致性分布式事务Atomikos实战 强一致性分布式事务解决方案要求参与事务的各个节点的数据时刻保 ...