0
点赞
收藏
分享

微信扫一扫

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

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

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

其中首先配置applicationContext.xml

ssh之雇员管理系统(1)-spring测试_spring_02ssh之雇员管理系统(1)-spring测试_spring_03View 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

ssh之雇员管理系统(1)-spring测试_spring_02ssh之雇员管理系统(1)-spring测试_spring_03View 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

ssh之雇员管理系统(1)-spring测试_spring_02ssh之雇员管理系统(1)-spring测试_spring_03View 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 }

 



作者:少帅

您的支持是对博主最大的鼓励,感谢您的认真阅读。

本文版权归作者所有,欢迎转载,但请保留该声明。


举报

相关推荐

0 条评论