aspose file tools*
The moose likes Spring and the fly likes Spring: Hello World Does Not Work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring: Hello World Does Not Work" Watch "Spring: Hello World Does Not Work" New topic
Author

Spring: Hello World Does Not Work

Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
Major Java Greenhorn here with Spring...

I'm following this Hello World guide to Spring to the letter:

http://www.developer.com/java/ejb/article.php/10931_3496416_2/A-Spring-Jump-Start.htm

However when I launch the main.java in Eclipse, it keeps on saying my Configuration File's id="greetingService" cannot find the class com.springinaction.chapter01.hello.

I made sure all the .java files were packaged within the com.springinaction.chapter01.hello too!

I not only installed the Eclipse Spring IDE, but I also have the spring.js and commons-logging.jar JAR files in my build path...

What am I doing wrong?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

We have no way of knowing, since you provided none of your code or configuration.
Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
I made sure that spring.JAR and commons-logging.JAR are in the Build-Path...

In main.java






In GreetingService.java




In GreetingServiceImpl





And finally in the Spring Configuration XML


hello2.xml





Pushed RUN on main.java in Eclipse - no go...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Compare:with:
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Moving this to the Spring forum.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1966
    
    7

I'm no Spring expert but the most likely problem is your location of your config file. Given what you have, the program will look for it in the root folder of the project if running directly from the IDE. If you are in doubt type in the full path like "C:\...." or whatever.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Naresh Bafna
Ranch Hand

Joined: Mar 23, 2007
Posts: 35
David Newton wrote:Compare:with:


I this the problem is what David mentioned.

Since the package name is com.springinaction.chapter01.hello.GreetingServiceImpl and the class name is GreetingServiceImpl the config should look like


and not



SCJP 5 - 94%
Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
Here's a screen of what the file structure looks like for this project file. I tried - what you said, but it still doesn't work - "can't find constructor."


[Thumbnail for $30CA716FDA683BE9.jpg]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't define a default constructor--the error message is correct.
Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
So I guess my question now is - how do I run this thing?

I push Run on main.java and this the following message:

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Define a default constructor.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Personally, I think your package naming is a little redundant, too, and counter to Java conventions (packages are all lower-case).
Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
So I got to figure out how to do a default constructor through a Spring Framework - interesting...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, if you're not doing constructor injection, your beans need to be instantiable without parameters.
Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 55
Aha! Fixed it!

Just added another constructor blurb in GreetingServiceImpl.java


Got Buenos Dias! message! Thanks everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring: Hello World Does Not Work
 
Similar Threads
Drools 4
Problem with "Spring in Action" Book First Example
Spring Hello World Error
ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
Running java with a classpath on cygwin