代码非常简单。如果缺少jar包将导致报错。

需要5个spring jar包和1个logging jar,否则报错。

org.springframework.asm.jar
org.springframework.core.jar
org.springframework.beans.jar
org.springframework.context.jar
org.springframework.expression.jar

定义一个接口,一个实现类。java project项目。

package ioc;
public interface HelloApi {
public void sayHello();
}
package ioc;
public class Hello implements HelloApi{
@Override
public void sayHello() {
System.out.println("Hello World!");
}
}
package ioc;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("helloworld.xml");
HelloApi helloApi = context.getBean("hello", HelloApi.class);
helloApi.sayHello();
}
}

  

<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- id 表示你这个组件的名字,class表示组件类 -->
<bean id="hello" class="ioc.Hello"></bean>
</beans>

不清楚如何找到该xml文件。

 ApplicationContext context = new ClassPathXmlApplicationContext("helloworld.xml"); 

spring ico的更多相关文章

  1. SpringBoot学习(二)——Spring的Java配置方式

    Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 一.@Configuration 和 @Bean Spring的Java配置方式是通过@Configuration和@Bean ...

  2. Spring IOC源代码具体解释之整体结构

    Spring ICO具体解释之整体结构 IOC介绍 IOC, spring的核心.贯穿Spring始终.直观的来说.就是由spring来负责控制对象的生命周期和对象间的关系,将对象之间的关系抽象出来. ...

  3. WPF控件--利用Winform库中的NotifyIcon实现托盘小程序

    WPF控件--NotifyIcon   运行界面如下所示:            图1                                             图2 代码很少,如下所示 ...

  4. Java系统高并发之Redis后端缓存优化

    一:前端优化 暴露接口,按钮防重复(点击一次按钮后就变成禁用,禁止重复提交) 采用CDN存储静态化的页面和一些静态资源(css,js等) 二:Redis后端缓存优化 Redis 是完全开源免费的,遵守 ...

  5. spring mvc 中自定义404页面在IE中无法显示favicon.ico问题的解决方法。

    此处用的是jsp,控制层用的是ModelAndView, 具体解决方法如下: @RequestMapping(value = "notfound", method = Reques ...

  6. 重新学习Spring注解——ICO

    02.组件注册-@Configuration&@Bean给容器中注册组件 03.组件注册-@ComponentScan-自动扫描组件&指定扫描规则 04.组件注册-自定义TypeFil ...

  7. 学记:spring boot使用官网推荐以外的其他数据源druid

    虽然spring boot提供了4种数据源的配置,但是如果要使用其他的数据源怎么办?例如,有人就是喜欢druid可以监控的强大功能,有些人项目的需要使用c3p0,那么,我们就没办法了吗?我们就要编程式 ...

  8. Spring MVC学习笔记——SiteMesh的使用(转)

    转自 SiteMesh的使用 SiteMesh的介绍就不多说了,主要是用来统一页面风格,减少重复编码的. 它定义了一个过滤器,然后把页面都加上统一的头部和底部. 需要先在WEB-INF/lib下引入s ...

  9. spring boot使用

    首先spring-boot是个服务框架,更加准确来讲是个微服务框架,实际上来说”微“并不“微”,spring-boot包含很多可嵌入的组件,通过这些组件可以来完成我们的服务, 以往我们使用Spring ...

随机推荐

  1. Linux firewalld 防火墙

    Linux firewalld 防火墙  简介 RHEL 7 系统中集成了多款防火墙管理工具,其中 firewalld(Dynamic Firewall Manager of Linux system ...

  2. libcurl返回常见错误码

    转载:https://blog.csdn.net/kenkao/article/details/46875571 转载:http://www.cnblogs.com/wainiwann/p/34929 ...

  3. Hi3519v101 SDK安装及升级

    安装SDK 1.解压tgz压缩包 将 Hi3519V101_SDK_Vx.x.x.x.tgz 压缩包放入共享文件夹中,并解压到Linux内部如 /sdk 目录下,因为在共享目录中编译容易出现各种错误. ...

  4. tp剩余未验证内容-6

    杂项 系统中的电感线圈元件, 虽然不消耗电能, 但是会 占用系统的容量(相当于占用资源但是不做事), 会使系统 的发电量的使用效率降低, 线路损耗增大, 发出同样有功用电量所需的设备容量扩大 将感性元 ...

  5. 【做题】agc006e - Rotate 3x3——分析&思维

    原文链接 https://www.cnblogs.com/cly-none/p/9800105.html 题意:给出一个三行\(n\)列的矩阵.问它能否由满足\(a_{ij} = 3(j-1) + i ...

  6. Win32汇编学习(6):键盘输入消息

    这次,我们将要学习WINDOWS程序是如何处理键盘消息的. 理论: 因为大多数的PC只有一个键盘,所以所有运行中的WINDOWS程序必须共用它.WINDOWS 将负责把击键消息送到具有输入焦点的那个应 ...

  7. Sql语句中IN和exists的区别及应用

    表展示 首先,查询中涉及到的两个表,一个user和一个order表,具体表的内容如下: user表: order表: in 确定给定的值是否与子查询或列表中的值相匹配.in在查询的时候,首先查询子查询 ...

  8. Lintcode376-Binary Tree Path Sum-Easy

    376. Binary Tree Path Sum Given a binary tree, find all paths that sum of the nodes in the path equa ...

  9. C# winform 选择文件保存路径

    1.winform 点击按钮选择文件保存的路径,效果如下图: 具体代码如下: private void button8_Click(object sender, EventArgs e) { Fold ...

  10. 页面Vue

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...