1. Create a new Loadpropertis class with the following contents:
Import Org.springframework.context.support.ClassPathXmlApplicationContext;
Import Junit.framework.TestCase;
public class Loadpropertis extends testcase{
private static classpathxmlapplicationcontext context= null;
private static String allproperties[] = {
"Applicationcontext-channel-test.xml", "Applicationcontext-common-test.xml"
};
protected void SetUp () throws exception{
Super.setup ();
if (context==null) {
context = new Classpathxmlapplicationcontext (allproperties);
}
}
protected void TearDown () throws exception{
Super.teardown ();
}
Protected Object Getbean (String beanname) {
if (Beanname = = null) {
throw new IllegalArgumentException (Beanname + "is null");
}
Return Context.getbean (Beanname);
}
}
2. NEW: Test01 class, the contents are as follows:
public class Test01 extends Loadpropertis {
Private Izybcorebs Zybcorebs;
protected void SetUp () throws exception{
Super.setup ();
Zybcorebs = (izybcorebs) this.getbean ("Zybcorebs");
}
protected void TearDown () throws exception{
Super.teardown ();
}
public void test01 () {
Curraccoinvo curraccoinvo = new Curraccoinvo ();
try {
Zybcorebs.curraccoquery (CURRACCOINVO);
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("failure");
}
}
}
3. Configuration file: The contents of the Application-channel-test.xml file are as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" >
<beans>
<bean id= "Zybcorebs" class= "Com.tansun.scf.zyb.intf.core.service.impl.ZybCoreBSImpl" >
<property name= "Busscommonbs" >
<ref bean= "Busscommonbs"/>
</property>
</bean>
<bean id= "Zybcmsbs" class= "Com.tansun.scf.zyb.intf.cms.service.impl.ZybCmsBSImpl" >
<property name= "Busscommonbs" >
<ref bean= "Busscommonbs"/>
</property>
</bean>
<bean id= "Busscommonbs" class= "Com.tansun.scf.common.service.impl.BussCommonBSImpl" >
<property name= "Sysparambs" >
<ref bean= "Sysparambs"/>
</property>
</bean>
</beans>
4. The configuration file Applicationcontext-common-test.xml content is as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" >
<beans>
<bean id= "Jndidatasource"
class= "Org.springframework.jndi.JndiObjectFactoryBean" >
<property name= "Jndiname" >
<value>OracleDataSource</value>
</property>
</bean>
<bean id= "Lobhandler"
class= "Org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init= "true"/>
</beans>
Where Applicationcontext-common-test.xml is the database configuration file and the database table XML file directory,
Applicationcontext-channel-test.xml is a method that calls the Java class's bean configuration information.
Unit test environment