This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring: Hello World Does Not Work

 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have no way of knowing, since you provided none of your code or configuration.
 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compare:with:
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Spring forum.

Mark
 
K. Tsang
Bartender
Posts: 3397
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naresh Bafna
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
$30CA716FDA683BE9.jpg
[Thumbnail for $30CA716FDA683BE9.jpg]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't define a default constructor--the error message is correct.
 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define a default constructor.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I got to figure out how to do a default constructor through a Spring Framework - interesting...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you're not doing constructor injection, your beans need to be instantiable without parameters.
 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha! Fixed it!

Just added another constructor blurb in GreetingServiceImpl.java


Got Buenos Dias! message! Thanks everyone!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic