Announcement Announcement Module
Collapse
No announcement yet.
Spring in console application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring in console application

    I am trying to implement some console application with Spring and hibernate..
    Here is the hibernate config:
    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:context="http://www.springframework.org/schema/context"    
       xmlns:tx="http://www.springframework.org/schema/tx"  xsi:schemaLocation="http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
       http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.1.xsd">    
          <tx:annotation-driven />    
          <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">        
            <property name="location" value="classpath:/hibernate.properties" />    
          </bean>    
          <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">        
            <property name="driverClassName" value="${hibernate.connection.driver_class}" />        
            <property name="url" value="${hibernate.connection.url}" />        
            <property name="username" value="${hibernate.connection.username}" />        
            <property name="password" value="${hibernate.connection.password}" />    
          </bean>    
          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">        
            <property name="dataSource" ref="dataSource" />        
            <property name="packagesToScan" value="com.data" />        
            <property name="hibernateProperties">            
              <props>                
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>                
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>                
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>                
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>                
                <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>            
              </props>        
            </property>    
          </bean>    
          <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">        
             <property name="sessionFactory" ref="sessionFactory" />    
          </bean>
    </beans>
    and spring's one:
    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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"     xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
      <context:annotation-config />    
       <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">        
        <property name="basename" value="com.Resources" />    
      </bean>    
      <bean id="eventsLogDao" class="com.EventsLogDAO"></bean>    
       <bean id="eventsLogService" class="com.EventsLogService"></bean>  
    </beans>
    the main method look like that:
    Code:
      
    public class App {      
        public static void main(String[] args) {        
            ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-service.xml", "spring-hibernate.xml");          
            try {            
               MessageSourceEx messageSource = new MessageSourceEx((ResourceBundleMessageSource) ctx.getBean("messageSource"));             leStorageService");            
               IEventsLogService eventsLogService = (IEventsLogService) ctx.getBean("eventsLogService");        
              // some code        
            }        
           catch (Exception e) {            
              e.printStackTrace();        
           }        
          finally {            
            ((ConfigurableApplicationContext)ctx).close();        
         }          
        System.exit(0);    
     }
    }
    And app fails during initialization with
    URL [rsrc:com.data/] cannot be resolved to absolute file path because it does not reside in the file system: rsrc:com.data/
    error..
    Any suggestions please? Thank you in advance
    Last edited by nKognito; May 20th, 2014, 10:43 AM.

  • #2
    This question has been asked on StackOverflow.

    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X