Spring(XML方式)简单入门
环境准备
- maven
- jdk
- Spring
- Eclipse
项目创建




pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cyb</groupId>
<artifactId>spring</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- spring 核心组件中的4个依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>5.0.7.RELEASE</version>
</dependency> <!-- 单元测试Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<finalName>spring</finalName>
<plugins>
<!-- 配置Maven的JDK编译级别 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
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.xsd">
<bean id="UserService" class="com.cyb.service.UserServiceImpl"></bean>
</beans>
UserService.java
package com.cyb.service;
public interface UserService {
void speak();
}
UserServiceImpl.java
package com.cyb.service;
public class UserServiceImpl implements UserService {
@Override
public void speak() {
System.out.println("陈彦斌博客:https://www.cnblogs.com/chenyanbin/");
}
}
TestUserService.java
package com.cyb.test; import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.cyb.service.UserService; public class TestUserService {
@Test
public void TestIoc() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
// 方式一
UserService service1 = context.getBean(UserService.class);
service1.speak();
// 方式二
UserService service2 = (UserService)context.getBean("UserService");
service2.speak();
}
}
项目结构

测试

Spring(XML方式)简单入门的更多相关文章
- Spring MVC之简单入门
一.Spring MVC简介: 1.什么是MVC 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计模式.它主要通过分离模型(Model).视图(View)及控制器(Contr ...
- 基于注解的Spring MVC的简单入门——简略版
网上关于此教程各种版本,太多太多了,因为我之前没搭过框架,最近带着两个实习生,为了帮他们搭框架,我只好...惭愧啊...基本原理的话各位自己了解下,表示我自己从来没研究过Spring的源码,所以工作了 ...
- Spring Cloud Feign 简单入门
Feign是一个生命是的web service 客户端,使用方式非常简单:接口+注解,spring cloud feign 对feign惊醒了增强使它支持了spring mcv注解. 示例(以下示例结 ...
- Spring Cloud Eureka简单入门
步骤: 1.创建父工程 2.创建EurekaServer工程 3.创建EurekaClient工程 父工程pom.xml <?xml version="1.0" encodi ...
- Spring Cloud Gateway简单入门,强大的微服务网关
我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 简介 见名知义,Spring Cloud Gateway是用于微服务场景的网关组件,它是基于Spring WebFlu ...
- XML第一次简单入门(Lab分析)
In this tutorial you will create a well-formed and verified XML file. Consider the XML document belo ...
- 6.Spring【AOP】XML方式
1.AOP术语 1. Joinpoint(连接点):所谓连接点是指那些被拦截到的点.在spring中,这些点指的是方法,因为spring只支持方法类型的连接点 2. Pointcut(切入点):所谓切 ...
- Spring AOP配置简单记录(注解及xml配置方式)
在了解spring aop中的关键字(如:连接点(JoinPoint).切入点(PointCut).切面(Aspact).织入(Weaving).通知(Advice).目标(Target)等)后进行了 ...
- 【java开发系列】—— spring简单入门示例
1 JDK安装 2 Struts2简单入门示例 前言 作为入门级的记录帖,没有过多的技术含量,简单的搭建配置框架而已.这次讲到spring,这个应该是SSH中的重量级框架,它主要包含两个内容:控制反转 ...
- Spring Boot【快速入门】简单案例
Spring Boot[快速入门] Spring Boot 概述 Build Anything with Spring Boot:Spring Boot is the starting point ...
随机推荐
- C 语言编程 — GDB 调试工具
目录 文章目录 目录 前文列表 代码调试 GDB 启动 GDB 交互命令 运行程序 暂停程序 设置断点 设置观察点 设置捕捉点 打印信息 查询运行信息 分割窗口 前文列表 <程序编译流程与 GC ...
- mongodb单个服务部署
mongodb3.2.8安装步骤: 1.系统准备 (1)redhat或cnetos6.2以上系统 (2)系统开发包完整 (3)ip地址和hosts文件解析正常 (4)iptables防火墙&S ...
- python的requests模块详解
原文链接:https://www.cnblogs.com/lanyinhao/p/9634742.html 1.模块说明 requests是使用Apache2 licensed 许可证的HTTP库. ...
- 本地项目文件上传到git
初始化项目: git init 与服务器项目关联:git remote add origin "http://**************************/r/ruoyi.git&q ...
- nginx源码安装步骤
1.安装依赖包 yum install -y gcc yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install ...
- requests + tkinter 获取网页数据
代码: from tkinter import * import requests window = Tk() window.geometry('500x350+500+100') window.ti ...
- CTFshow-Crypto(1-5)
1密码学签到 自己倒序 在线网站倒序 文字倒序工具,在线文字倒序 (qqxiuzi.cn) python脚本 a = '}wohs.ftc{galf' print(a[::-1], end=" ...
- AutoLayout与UIbutton
1.UIButton贴近右边,高度固定,宽度跟随标题变化 class TestButton: UIButton { } class ViewController: UIViewController { ...
- C++笔记(3)引用
引用是变量的别名.也就是说,它是某个已存在变量的另一个名字.一旦把引用初始化为某个变量,就可以使用该引用名称或变量名称来指向变量. 1.创建引用 int i = 0; int& r = i;/ ...
- Qt初始化代码基本说明
参考视频:黑马程序员https://www.bilibili.com/video/BV1XW411x7NU?p=4 1 工程基本介绍 按照这个基本步骤(https://www.cnblogs.com ...