Announcement Announcement Module
No announcement yet.
executable jar, NoSuchBeanDefinition exception Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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){"Could not load Spring application context. Make sure the file exists and is on the class path");
    } 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=""
    xmlns:xsi="" xmlns:util=""

    <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 id="OracleDAO" class="org.obis.dao.OracleDAO">
    <property name="dataSource"><ref bean="OracleDataSource"/></property>


    Thanks for any help or guidance. I'm stuck so even wild guesses would be appreciated.


  • #2
    oracleDAO = (OracleDAO)ctx.getBean("OracleDAO") ; <== this line throws the exception

    Try this

    oracleDAO = (OracleDAO)ctx.getBean("oracleDAO") ; <== this line throws the exception


    • #3
      do you added oracle jdbc jar for example ojdbc14- in your maven dependency ?


      • #4
        I'd start by posting the full stack trace of the error, that might help. When you post code/xml config/stack traces please remember to use [ CODE] [ /CODE] tags so that what you post remains readable.


        • #5
          also put your java class code see if it extends spring dao support class.