Announcement Announcement Module
Collapse
No announcement yet.
executable jar, NoSuchBeanDefinition exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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){
    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

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


    Try this

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

    Comment


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

      Comment


      • #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.

        Comment


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

          Comment

          Working...
          X