LAB-4939: Spring 3 Annotation-based DI, Exercise 3

5 views
Skip to first unread message

Vance

unread,
Aug 13, 2011, 4:43:46 PM8/13/11
to springframework-codecamp
I'm having trouble getting Exercise 3 for LAB-4939 to work. Here's the
output I get when I try to run the 'di_configuration_XML' project:


log4j:WARN No appenders could be found for logger
(org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
accountRepository.findById("A123").getBalance() = 1000.0
accountRepository.findById("C456").getBalance() = 0.0
Exception in thread "main" java.lang.NoClassDefFoundError: org/
hamcrest/CoreMatchers
at com.javapassion.examples.account.Main.main(Main.java:33)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.CoreMatchers
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more

Vance

unread,
Aug 13, 2011, 4:53:53 PM8/13/11
to springframework-codecamp
Ok, I fixed that problem by going to www.findjar.com Web site and
downloading and adding the following JAR file:

org.apache.servicemix.bundles.hamcrest-1.2-dev1_1.jar

Now when I try to run the app, I get the following stack trace
complaining about a missing JUnit class:

log4j:WARN No appenders could be found for logger
(org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
accountRepository.findById("A123").getBalance() = 1000.0
accountRepository.findById("C456").getBalance() = 0.0
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/
Assert
at com.javapassion.examples.account.Main.main(Main.java:33)
Caused by: java.lang.ClassNotFoundException: org.junit.Assert
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more


Vance

unread,
Aug 13, 2011, 4:58:52 PM8/13/11
to springframework-codecamp
I went to findjar.com again, and found out that the 'org.junit.Assert'
class is part of the following JAR files:

[CLASS] junit-4.1.jar.org.junit.Assert
[CLASS] junit-4.4.jar.org.junit.Assert

My project is using junit-4.7.jar for some reason.


On Aug 13, 4:53 pm, Vance <vance0...@gmail.com> wrote:
> Ok, I fixed that problem by going towww.findjar.comWeb site and

Vance

unread,
Aug 13, 2011, 5:00:29 PM8/13/11
to springframework-codecamp
Actually that 'Assert' class should be part of junit-4.7.jar...


On Aug 13, 4:58 pm, Vance <vance0...@gmail.com> wrote:
> I went to findjar.com again, and found out that the 'org.junit.Assert'
> class is part of the following JAR files:
>
> [CLASS] junit-4.1.jar.org.junit.Assert
> [CLASS] junit-4.4.jar.org.junit.Assert
>
> My project is using junit-4.7.jar for some reason.
>
> On Aug 13, 4:53 pm, Vance <vance0...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Ok, I fixed that problem by going towww.findjar.comWebsite and

Vance

unread,
Aug 13, 2011, 5:10:00 PM8/13/11
to springframework-codecamp
I can't get the 'di_Configuration_Java' project discussed in Exercise
4 to work, either. I've gotten the same error messages as I did for
the Exercise 3 project.

Vance

unread,
Aug 13, 2011, 5:38:33 PM8/13/11
to springframework-codecamp
Ok, I've got the 'di_Configuration_Java' project to work. I ended up
doing the following (and this approach also works for the
'di_Configuration_XML' project):

1) Create a 'lib' directory within the project
2) Copy the 'junit-4.7.jar' file to this directory
3) Update the project properties so this JAR file (along with the
'hamcrest' JAR file) is added to the 'Libraries' tabpage of the 'Java
Build Path' page of the project properties window
4) Clean and rebuild the project
5) Run the 'main()' method of the 'Main.java' class

Sang Shin

unread,
Aug 14, 2011, 10:01:18 AM8/14/11
to vanc...@gmail.com, springframework-codecamp
On 8/13/2011 5:38 PM, Vance wrote:
> Ok, I've got the 'di_Configuration_Java' project to work. I ended up
> doing the following (and this approach also works for the
> 'di_Configuration_XML' project):
>
> 1) Create a 'lib' directory within the project
> 2) Copy the 'junit-4.7.jar' file to this directory
> 3) Update the project properties so this JAR file (along with the
> 'hamcrest' JAR file) is added to the 'Libraries' tabpage of the 'Java
> Build Path' page of the project properties window
> 4) Clean and rebuild the project
> 5) Run the 'main()' method of the 'Main.java' class
>

Thanks. In theory, the pom.xml should take care of all this. For the
sake of this exercise,
I removed the dependency on hamcrest. New lab zip file has been uploaded.

-S


--
-------------------------------------------------------------------
Sang Shin, sangshi...@gmail.com
Founder and Chief Instructor of JPassion.com
http://JPassion.com/portal/instructors/sang-shin-schedule (Bio)
http://www.linkedin.com/in/javapassion (Linkedin)
http://twitter.com/javapassion (Tweeter)
Life is worth living... with Passion!
----------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages