zoukankan      html  css  js  c++  java
  • ssh之雇员管理系统(1)spring测试

    
    
    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 }

    作者:少帅

    出处:少帅的博客--http://www.cnblogs.com/wang3680

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

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

    支付宝 微信
  • 相关阅读:
    learnyou 相关网站
    hdu 3038 How Many Answers Are Wrong
    hdu 3047 Zjnu Stadium 并查集高级应用
    poj 1703 Find them, Catch them
    poj 1182 食物链 (带关系的并查集)
    hdu 1233 还是畅通工程
    hdu 1325 Is It A Tree?
    hdu 1856 More is better
    hdu 1272 小希的迷宫
    POJ – 2524 Ubiquitous Religions
  • 原文地址:https://www.cnblogs.com/wang3680/p/3075896.html
Copyright © 2011-2022 走看看