linuxerwang
Feb 11th, 2006, 12:10 PM
Hello, all
I wrote the following codes, but it failed to work:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>org.postgresql.Driver</value>
</property>
......
<target name="initdb" depends="compile, mapping">
<taskdef name="SystemInit" classname="tests.SystemInit" classpathref="classpath">
</taskdef>
<SystemInit configPath="${web}/WEB-INF/config" dataPath="${base}/initdata"/>
</target>
private void setUp() throws Exception {
System.out.println("---> "+Class.forName("org.apache.commons.dbcp.BasicDataSource").newInstance());
appContext = new FileSystemXmlApplicationContext(
new String[] {
configPath + "/dataAccessContext-local.xml",
configPath + "/applicationContext.xml"
}
);
......
}
And when run it through ant (from the command line), it gives exception:
[SystemInit] org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'dataSource' defined in file [/home/test/project/web/WEB-INF/config/dataAccessContext-local.xml]: Bean class [org.apache.commons.dbcp.BasicDataSource] not found; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
It's surprising that Class.forName can find the same class but Spring can't find it. Seems some contextloader problem, but I don't know how to solve it.
I am using spring 1.2.6.
Help me please, thank you very much.
I wrote the following codes, but it failed to work:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>org.postgresql.Driver</value>
</property>
......
<target name="initdb" depends="compile, mapping">
<taskdef name="SystemInit" classname="tests.SystemInit" classpathref="classpath">
</taskdef>
<SystemInit configPath="${web}/WEB-INF/config" dataPath="${base}/initdata"/>
</target>
private void setUp() throws Exception {
System.out.println("---> "+Class.forName("org.apache.commons.dbcp.BasicDataSource").newInstance());
appContext = new FileSystemXmlApplicationContext(
new String[] {
configPath + "/dataAccessContext-local.xml",
configPath + "/applicationContext.xml"
}
);
......
}
And when run it through ant (from the command line), it gives exception:
[SystemInit] org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'dataSource' defined in file [/home/test/project/web/WEB-INF/config/dataAccessContext-local.xml]: Bean class [org.apache.commons.dbcp.BasicDataSource] not found; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
It's surprising that Class.forName can find the same class but Spring can't find it. Seems some contextloader problem, but I don't know how to solve it.
I am using spring 1.2.6.
Help me please, thank you very much.