Win a copy of Java Challengers this week in the Java in General 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

New to Spring

 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am new to Spring and following Spring in action 3rd edition. I am trying to make first example from it but it is not working. I spend 2 days on it but dint figured it out.
Any idea?









Getting following error while running:

 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that your Java version is Java 8 but Spring version is 3. Is it? If so, use Spring 4.
Alternatively, install Java 7 as your default JRE, and continue with Spring 3.
The error from "org.springframework.asm.ClassReader" is a giveaway that it's something to do with java class file format, and sure enough it looks like asm version in spring 3 can't handle java 8 compiled classes.
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh beauty.. It worked like a charm.. Thanks..

But i am confused, when i used another example in Java-8, it worked normal. Why so? Why not error in this case as i had
in previous example?





 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In 1st example, a bean is being instantiated using constructor injection. Apparently, for that, spring uses the asm library which can do class file reading/writing.
In 2nd example, there is no constructor injection and so there's no need to do any class file reading.

The deeper question is why spring is using asm at all and not just plain java reflection? The call to "LocalVariableTableParameterNameDiscoverer.getParameterNames" suggests that spring is doing some parameter matching based on parameter names as declared in source code, and the only way to get those parameter names is by reading the .class file directly. I don't think java reflection API can provide parameter names.

The even deeper question is why do parameter matching at all? I have no idea why. I had assumed constructor injection is done purely on the order of the constructor-arg elements. I'm surprised that parameter names are involved in the logic.

Anybody here has a better explanation for parameter matching?
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are we talking about parameter name as method/constructor parameter name or instance variable?

If it is about method/constructor parameter name then we can do the same using refection API.

With parameter matching i guess it is required to validate the type of dependency we are injecting to make sure
it is right.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic