001. Spring HelloWorld
来源:互联网 发布:监控员工上网的软件 编辑:程序博客网 时间:2024/06/15 15:37
1、创建Java项目:File -> New -> Java Project
2、引入必要jar包,项目结构如下
3、创建HelloWorld服务类HelloWorld.java
package com.spring.service;public class HelloWorld { public void welcome() { System.out.println("Welcome to spring framework!"); }}
4、创建Spring配置文件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="helloWorld" class="com.spring.service.HelloWorld"></bean></beans>
5、创建Spring测试类SpringUnit.java
package com.spring.junit;import org.junit.Test;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.spring.service.HelloWorld;public class SpringUnit { @Test public void test() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld"); helloWorld.welcome(); ctx.close(); }}
6、测试结果
... 省略Spring日志信息 ...Welcome to spring framework!... 省略Spring日志信息 ...
阅读全文
0 0
- 001. Spring HelloWorld
- 001. Spring MVC HelloWorld
- Spring helloworld
- spring helloworld
- spring helloworld
- Spring -- HelloWorld
- spring helloworld
- Spring HelloWorld
- Spring--HelloWorld
- spring HelloWorld!
- spring-HelloWorld
- spring helloworld
- Spring-HelloWorld
- spring HelloWorld
- spring-1:Spring helloWorld
- Spring 之spring helloworld
- 从HelloWorld到Spring
- Spring-HelloWorld搭建
- Java设计模式——责任链模式(Chain of Responsibility)
- 计算广告学总结
- Java设计模式——适配器模式
- iOS 二维码扫描 原生版
- HTML5 Web SQL 对数据库的操作
- 001. Spring HelloWorld
- Android系统机制
- Window7搭建Telnet服务器
- PyQt-3
- 机器学习(1)--logistic回归和softmax回归
- css
- iOS 项目的目录结构能看出你的开发经验
- java实现多继承
- 简析TCP协议--三次握手和四次挥手