Announcement Announcement Module
Collapse
No announcement yet.
console java example with hibernate and spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • console java example with hibernate and spring

    Hi All,

    Am beginner to spring technology , application

    am trying to make a small example this example is not web application example , it is java console application in which am trying to insert hard code data into the database using the hibernate ,

    i have the following 2 questions
    1)Can i use spring and hibernate to manage such concole application or spring and hibernate are used to manage only web applications

    2)any one can refer me any site which can guide to achieve such samll example or any hints for doing that

    Thanking you in Advance

  • #2
    Document root element "beans", must match DOCTYPE root "null".

    Hi All,


    I have tried to start learning spring and i have tried to do the first example

    but am getting error



    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Line 4 in XML document from file [E:\new-clean-eclipse-new-apache\workspace\SpringHelloWorldExampleNew\applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
    org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
    	at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    	at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
    	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    	at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
    	at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
    	at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
    	at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:222)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:81)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:89)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:74)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:65)
    	at com.javasrc.hellospring.HelloSpringBean.main(HelloSpringBean.java:23)

    as i have read from a post http://forum.springframework.org/showthread.php?t=37877

    that the problem in the spring version


    but how i can know which spring version am using ?

    I really dont know which spring version am using , i have got the libraries from one of my friends projects

    can any one help me to fix this issue


    by the way i have got this simple example from the link

    http://www.informit.com/guides/conte...ava&seqNum=447



    here is my code which is only 2 files

    1)applicationContext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	   xmlns="http://www.springframework.org/schema/beans"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    	<bean id="helloSpringBean" class="com.javasrc.hellospring.HelloSpringBean" >
    		<property name="message" value="Hello, Spring" />
    	</bean>
    </beans>
    2)HelloSpringBean.java

    Code:
    package com.javasrc.hellospring;
    
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    
    import org.springframework.context.ApplicationContext; 
    
    public class HelloSpringBean 
    {
    	private String message;
    	
    	public void setMessage( String message )
    	{
    		this.message = message;
    	}
    	
    	public String getMessage()
    	{
    		return this.message;
    	}
    	
    	public static void main( String[] args )
    	{
    		ApplicationContext context = new FileSystemXmlApplicationContext( "applicationContext.xml" );
    		HelloSpringBean helloSpringBean = ( HelloSpringBean )context.getBean( "helloSpringBean" );
    		System.out.println( helloSpringBean.getMessage() );
    		
    	}
    }

    Thanking you in advance

    Comment


    • #3
      Hi All,


      Thanks alot I have fixed the issue ,

      I have changed the applicationContext.xml to the following


      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
      <beans>
      	<bean id="helloSpringBean" class="com.javasrc.hellospring.HelloSpringBean" >
      		<property name="message" value="Hello, Spring" />
      	</bean>
      </beans>

      It is working now

      Comment

      Working...
      X