-
Feb 15th, 2011, 11:06 AM
#1
executable jar, NoSuchBeanDefinition exception
I'm using the Spring Container to set up a DAO for a small application. I tested with Eclipse and everything
worked fine. I used Maven to create an executable jar file for deployment and the deployed app is throwing
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'OracleDAO' is defined.
Here is the complete code segment that produces the exception:
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext .xml");
if (ctx==null){
log.info("Could not load Spring application context. Make sure the file exists and is on the class path");
System.exit(0);
} else {
String[] beans = ctx.getBeanDefinitionNames() ;
for ( int i=0; i<beans.length; i++) {
System.out.println("Spring managed Bean=" + beans[i]);
}
}
// set the Oracle DAO
oracleDAO = (OracleDAO)ctx.getBean("OracleDAO") ; <== this line throws the exception
The strange part of this is that the datasource objects are created but the daos that use the data source objects are not
found. The dao classes are part of the application while the datasource classes are not. That is the only clue to what
is going.
Is this some sort of classpath problem, i.e. Spring does not know where to find OracleDAO class in the executable jar?
Here is my application context (with connection params removed):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<bean id="OracleDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="..."/>
<property name="url" value="jdbc:oracle:thin: ... />
<property name="username" value="..."/>
<property name="password" value="..."/>
</bean>
<bean id="OracleDAO" class="org.obis.dao.OracleDAO">
<property name="dataSource"><ref bean="OracleDataSource"/></property>
</bean>
</beans>
Thanks for any help or guidance. I'm stuck so even wild guesses would be appreciated.
-=beeky
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules