代码非常简单。如果缺少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. WebBench 安装使用

    介绍 WebBench是有名的网站压力测试工具,由Lionbridge公司开发,最多可以模拟3万个并发连接去测试网站的负载能力.. 安装 系统:Linux Centos 7.4 x64 版本:webb ...

  2. es安装elasticsearch-sql插件

    根据现有ES版本,安装对应版本的插件 [es@hxl ~]$ cd elasticsearch[es@hxl elasticsearch]$ ./bin/elasticsearch-plugin in ...

  3. shell实现自动部署两台tomcat项目Ⅱ

    本次分为3个脚本, scp.sh放进第一台机器(负责传输文件), schenglee.sh放进第一台机器(自动部署), schenglee2.sh放进第二台机器(自动部署) 环境 tomcat1: 1 ...

  4. XGpio函数

    头文件 #include"xgpio.h" int XGpio_Initialize(XGpio * InstancePtr, u16 DeviceId) 功能:初始化GPIO 参 ...

  5. Centos7 安装并配置redis

    一. 安装 操作系统:Centos 7. 最小化安装 redis版本: 4.0.2 服务器地址:*** 安装过程: 安装wget, yum -y install wget 2.  下载redis wg ...

  6. galera+mycat高可用集群部署

    环境描述 10.30.162.29  client 环境描述 10.30.162.29 client 10.30.162.72 mysql1 10.30.162.73 mysql2 10.30.162 ...

  7. JAVA中字符串比较equals()和equalsIgnoreCase()的区别

    1.使用equals( )方法比较两个字符串是否相等(区分大小写) 2.使用equalsIgnoreCase( )方法比较两个字符串是否相等(不区分大小写) boolean equalsIgnoreC ...

  8. git修改本地和远程仓库名称的解决方法

    说明:旧的仓库名称为mygit,新的仓库名称为Blog 1.修改远程仓库名称 在GitHub上进入要修改的仓库,找到settings,修改名称. 2.修改本地仓库名称 进入存放项目的目录,我的是/ho ...

  9. 跟敲MySQL数据库实用教程

    MySQL数据库操作 创建数据库 create database if not exists test; 查看数据库 show databases; show databases [ like wil ...

  10. 在线自动创建springboot工程

    https://start.spring.io/