3

I am reading spring document and I couldn't understand below statement from c-namespace section in the reference document

For the rare cases where the constructor argument names are not available (usually if the bytecode was compiled without debugging information), one can use fallback to the argument indexes

My questions are :

  1. In what cases constructor argument is not available.
  2. What does it mean that -byte code compiled without debugging information. Can be it checked using eclipse ?

I was checking for this over web, but could get any reference. I found Constructor injection using c:namespace but it didn't explain any thing

skaffman
  • 398,947
  • 96
  • 818
  • 769
Anveshan
  • 614
  • 1
  • 9
  • 21

2 Answers2

2

If the class in question was compiled by javac without the -g flag ("debug info" - see javac docs), then the compiled class bytecode will not contain the names of the constructor parameters. This means that Spring cannot use reflection to match the constructor parameter names, so you need to inject them by position (i.e. by index) instead.

It's up the build environment that generates the compiled bytecode to ensure that debug info is supplied. Once the code is compiled, there's nothing you can do to retrieve that information, short of recompiling it.

See also What does the javac debugging information option -g:vars do?

Community
  • 1
  • 1
skaffman
  • 398,947
  • 96
  • 818
  • 769
2

Constructor argument names are only available if the class is compiled with variable debugging information. When using javac, this is the -g:vars option. In Eclipse, this is Windows > Preferences > Java > Compiler > Add variable attributes to generated class files.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90