• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to run java configuration based Spring application ?

 
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very new to Spring framework. I am reading Spring in Action. I am trying to code auto wiring beans. But I am not able to run the application. Here is my code[it is same as in the book]









Now the problem with the main method. I actually do not how to run this application from the main method.



What is the procedure in main method that I could run the application.

Thank you.
 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muztaba Hasanat,

Take a look at your code in main method



So this will look for CDPlayerConfig but your config class is empty. Please check that out
 
Muztaba Hasanat
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Partheban Udayakumar wrote:Muztaba Hasanat,

Take a look at your code in main method



So this will look for CDPlayerConfig but your config class is empty. Please check that out


Thank you. I have figure that out.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muztaba Hasanat,

Welcome. Glad that I was able to help you out
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I find the exchange egnimatic.
>So this will look for CDPlayerConfig but your config class is empty. Please check that out
>Thank you. I have figure that out.
But that config class be empty is coming directly from the book referred to. It is intended to be empty for the purpose of demonstrating annotation based configuration (instead of xml based configuration). So that is no problem and the book is not mistaken. I figure it should be noted so that other readers might not be lead to think that is a problem. So "figure out"?, could well be, but definitely not something related to the emptiness of the config class!

The book provided a JUnit based testing, so a question on how to test in the appliation's main may be legitimate and sometimes useful. This is how to test the SgtPlayer part.

This will show up "Play Pink Floyd" demonstrating that the @Component effectively have the spring container instantiated an instance of SgtPlayer...

Now, your addition testing with CDPlayerTest, which seems not directly from the book, contains a problem. You have to similarly annotate the class with @Component annotation. After that, the private field CompactDise cd (CompactDisc from the book, but you did it consistently with a "e" and that's ok) will be instantiated because of the @Autowired annotation - that is the point again of the demonstration. And the test in the main will take these lines to confirm it.

And it echoes out "Yahoo..." to confirm cd being non-null. Hope this makes this thread make more sense.
reply
    Bookmark Topic Watch Topic
  • New Topic