This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

error in a simple hibernate application

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOrry for the incorrect subject line...
it is a spring application only
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic