ssh之雇员管理系统(1)-spring测试

本文介绍了一个简单的Spring配置案例,通过创建一个包含两个类(TestServcie和服务测试类Test)的com.wang.ssh包,并配置applicationContext.xml来实现对TestServcie对象的注入和测试。


  1. 建包名为com.wang.ssh 包下面有两个类 ,一个是测试类,更一个是测试对象
  2. applicationContext.xml是配置Spring文件,ok这样就可以测试啦。。

其中首先配置applicationContext.xml

View Code
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4         xmlns:context="http://www.springframework.org/schema/context"
 5         xmlns:tx="http://www.springframework.org/schema/tx"
 6         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 7                 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
 8                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
 9 <!--配置testservice对象测试Spring配置是否成功 -->
10 <bean id="testServcie" class="com.wang.ssh.TestServcie">
11     <property name="name" value="test" />
12 </bean>
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 </beans>
TestService.java
View Code
 1 package com.wang.ssh;
 2 
 3 public class TestServcie {
 4 
 5     private String name;
 6 
 7     public String getName() {
 8         return name;
 9     }
10 
11     public void setName(String name) {
12         this.name = name;
13     }
14 }
Test.java
View Code
 1 package com.wang.ssh;
 2 
 3 import org.springframework.context.ApplicationContext;
 4 import org.springframework.context.support.ClassPathXmlApplicationContext;
 5 
 6 public class Test {
 7     public static void main(String[] args) {
 8         /**
 9          * 测试Spring配置是否成功
10          */
11         ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
12         TestServcie testServcie = (TestServcie)ac.getBean("testServcie");
13         System.out.println(testServcie.getName()+"***"); 
14     }
15 
16 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值