-
建包名为com.wang.ssh 包下面有两个类 ,一个是测试类,更一个是测试对象
- 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 }