Results 1 to 2 of 2
  1. #1
    cgk_js is offline Member
    Join Date
    Oct 2012
    Posts
    21
    Rep Power
    0

    Default applicationContext could path could not be resolved

    am getting this error, when i define the the applicationContext inside my spring simple database connection code.

    but when i place the applicationContext where the java (DatabaseTestConnection.java) resides, it connects without any issues.

    Error


    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

    Source

    applicationContext.xml

    XML Code:
    <?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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    
    <!--bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/jdbc.properties" />
    
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.url}"
    p:username="${jdbc.username}"
    p:password="${jdbc.password}" /-->
    
    <bean id="databaseTestConnection" class="DatabaseTestConnection">
    <property name="dataSource" ref="externalDataSource"/>
    </bean>
    
    <bean id="externalDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" scope="singleton"     destroy-method="close">
    <property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
    <property name="url" value="jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=C://Users//gopc//Documents//odbc_sql.accdb"/>
    <property name="username" value=""/>
    <property name="password" value=""/>
    </bean>
    
    <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
    
    </beans>

    DatabaseTestConnection.java

    Java Code:
    import java.util.*;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;
    
    import javax.sql.DataSource;
    import org.springframework.jdbc.core.JdbcTemplate;
    
    public class DatabaseTestConnection {
    
    private JdbcTemplate jt;
    
    public void setDataSource(DataSource dataSource) {
        this.jt = new JdbcTemplate(dataSource);
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
        DatabaseTestConnection bn = (DatabaseTestConnection) bf.getBean("databaseTestConnection");
        int count = bn.jt.queryForInt("select count(*) from log_entry");
        System.out.println("cgk count:" + count);
    
        List <Map <String,Object> > ob = bn.jt.queryForList("select * from log_entry", args);
        System.out.println("cgk size:" + ob.size());
        for (Map<String,Object> entry: ob )
        {
            System.out.println("ID:" + entry.get("ID"));
            System.out.println("DateCol:" + entry.get("DateCol"));
            System.out.println("Completed:" + entry.get("Completed"));
        }
    
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: applicationContext could path could not be resolved

    Posting that lot is pretty irrelevant, as the error is quite clear.
    It cannot find your applicationContext.xml, which means it's in the wrong place.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 12-17-2012, 01:44 PM
  2. Replies: 1
    Last Post: 11-14-2011, 04:39 PM
  3. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 12:31 PM
  4. Replies: 2
    Last Post: 06-12-2007, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •