spring学习之第一个spring程序
spring的入门程序
1.在Eclipse中创建Java项目,并将spring的四个核心包和依赖包添加到src里,发布到类路劲下,项目如图所示:

2.UserDao程序如下:
package com.itheima.ioc;
public interface UserDao {
public void say();
}
3.UserDaoImpl如下:
package com.itheima.ioc;
public class UserDaoImpl implements UserDao {
@Override
public void say() {
System.out.println("UserDao say hello Word!");
}
}
4.applicationContext.xm如下
配置文件的名称可以随便写,通常在实际开发中都写成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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
<!-- 将指定的类配置给Spring,让Spring创建其对象的实例 -->
<bean id="userDao" class="com.itheima.ioc.UserDaoImpl"/>
</beans>
5.测试程序如下:
package com.itheima.ioc; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class IocTest {
public static void main(String[] args) {
//1.初始化spring容器,加载配置文件
ApplicationContext applicationContext=
new ClassPathXmlApplicationContext("applicationContext.xml"); //2.通过容器来获取userDao实例
UserDao userDao=(UserDao) applicationContext.getBean("userDao"); //3.调用实例的方法
userDao.say();
}
}
测试结果如下:

spring学习之第一个spring程序的更多相关文章
- Spring学习之第一个AOP程序
IOC和AOP是Spring的两大基石,AOP(面向方面编程),也可称为面向切面编程,是一种编程范式,提供从另一个角度来考虑程序结构从而完善面向对象编程(OOP). 在进行 OOP 开发时,都是基于对 ...
- Spring学习之第一个Spring MVC程序(IDEA开发环境)
回顾Java平台上Web开发历程来看,从Servlet出现开始,到JSP繁盛一时,然后是Servlet+JSP时代,最后演化为现在Web开发框架盛行的时代.一般接触到一个新的Web框架,都会想问这个框 ...
- Spring学习(三)——Spring中的依赖注入的方式
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...
- Spring学习(二)——Spring中的AOP的初步理解[转]
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring. ...
- Spring学习(二)——Spring中的AOP的初步理解
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...
- spring 学习(四): spring 的 jdbcTemplate 操作
spring 学习(四): spring 的 jdbcTemplate 操作 spring 针对 javaee 的每一层,都提供了相应的解决技术,jdbcTemplate 的主要操作在 dao 层. ...
- Spring学习之——手写Spring源码V2.0(实现IOC、D、MVC、AOP)
前言 在上一篇<Spring学习之——手写Spring源码(V1.0)>中,我实现了一个Mini版本的Spring框架,在这几天,博主又看了不少关于Spring源码解析的视频,受益匪浅,也 ...
- swift学习:第一个swift程序
原文:swift学习:第一个swift程序 最近swift有点火,赶紧跟上学习.于是,个人第一个swift程序诞生了... 新建项目
- Spring学习之第一个hello world程序
Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development a ...
随机推荐
- 二十四、JavaScript之取字符串长度
一.代码如下 二.效果如下 <!DOCTYPE html> <html> <meta http-equiv="Content-Type" conten ...
- 031-PHP获取图像信息
<?php list($width, $height, $type, $attr) = getimagesize("plane.jpg"); echo "宽度为:& ...
- win10,64位操作系统安装mysql-8.0.16经验总结(图文详细,保证一次安装成功)
文章目录 1.mysql下载 2.解压及配置文件 3.启动MySQL数据库 4.登录 MySQL 5.配置系统环境变量 6.mysql-8.0.16修改初始密码 机器配置: win10,64位: my ...
- C++ 把数组的元素乘以2在输出
#include<iostream> using namespace std; int main(){ ] = { , , , , }; ; ; i < ; i++) { ) { s ...
- GDI+应用2
在上一篇里已经向大家介绍了如何使用GDI+绘制简单的图像,这一片继续向大家介绍其它一些绘图知识.1.首先我们来看下上一片中我们使用过的Pen.Pen的属性主要有: Color(颜色),DashCap( ...
- 实验吧-隐写-FIVE1、so beautiful so white(文件头修改)
FIVE1 下载图片,kali下foremost恢复文件,将得到的图片用Winhex打开进行观察,发现最后面有一段貌似是代码的东西. LS0uLi4gIC4tICAuLi4uLiAgLS0uLi4gI ...
- Python MongoDB 插入文档
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Spring 事件(1)- 内置事件
Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...
- mysql 手动把字段设置为null
在根据经纬度计算距离的时候,发现有的视频点距离我当前位置的距离计算出来的为0,有的距离计算出来是几千公里,仔细看下数据库,发现了问题所在 计算出来几千公里的视屏点的经纬度是空不是null,然后我们手动 ...
- composer install、require、update的区别