File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes error in a simple hibernate application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "error in a simple hibernate application" Watch "error in a simple hibernate application" New topic
Author

error in a simple hibernate application

surima jain
Greenhorn

Joined: Jan 01, 2009
Posts: 2
hi
i'm completely new to spring framework.i've developed a simple web application in spring.Putting the source code here.


HelloCLient.java
----------------

package com.infotech.springtest;

import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
import org.springframework.core.io.*;

public class HelloClient {

public static void main(String[] args) throws Exception{
try
{
System.out.println("please Wait.");
Resource res= new FileSystemResource("hello.xml");
System.out.println("Resource OK");
BeanFactory factory=new XmlBeanFactory(res);
System.out.println("BeanFactory OK.");
Hello bean1=(Hello)factory.getBean("Hello");
String s1=bean1.sayhello("3i-infotech");
System.out.println(s1);
}
catch(Exception e)
{

}
}
}

Hello.java
-----------

package com.infotech.springtest;

public interface Hello {
public String sayhello(String a);
}
HelloImp.java
--------------

package com.infotech.springtest;

/**
* @author 50956
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class HelloImpl implements Hello{
private String greeting;
public HelloImpl()
{
}
public HelloImpl(String s)
{
this.greeting=s;
}

public String sayhello(String a) {
// TODO Auto-generated method stub
return greeting+a;
}

/**
* @param greeting The greeting to set.
*/
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}

hello.xml
----------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "D:\spring-beans.dtd">
<beans>
<bean id="Hello" class="com.infotech.springtest.HelloImpl">
<property name="greeting">
<value>Hello World</value>
</property>
</bean>
</beans>



Upon running HelloClient.java i'm getting the output as

please Wait.
Resource OK
Jan 2, 2009 11:56:14 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader
INFO: Loading XML bean definitions from file [C:\KastleUniversalLending_SuiteRAD\SpringTest\hello.xml]
surima jain
Greenhorn

Joined: Jan 01, 2009
Posts: 2
SOrry for the incorrect subject line...
it is a spring application only
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Why not put something into the Exception handler because just catching and doing nothing is not a good idea. You are not seeing any exceptions, and will never know. The exception stacktrace will probably tell you everything.

Also, I recommend using ApplicationContext instead of BeanFactory, because that is the way things are now being done in Spring. The old way was with just a BeanFactory, but that is really pre Spring 2.0 days and we are already at Spring 2.5.6 and soon to be Spring 3.0

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

surima jain wrote:SOrry for the incorrect subject line...
it is a spring application only


You can fix it easily. Just click the button on your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error in a simple hibernate application