有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

spring参考文档中的java Cnamespace部分

我正在阅读spring文档,无法理解下面来自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

我的问题是:

  1. 在什么情况下构造函数参数不可用
  2. 没有调试信息编译的字节代码是什么意思。可以用eclipse检查吗

我在网上查了一下,但能找到任何参考资料。我找到了Constructor injection using c:namespace,但它不能解释任何事情


共 (2) 个答案

  1. # 1 楼答案

    构造函数参数名称仅在使用变量调试信息编译类时可用。使用javac时,这是-g:vars选项。在Eclipse中,这是Windows > Preferences > Java > Compiler > Add variable attributes to generated class files

  2. # 2 楼答案

    如果所讨论的类是由javac编译的,而没有-g标志(“调试信息”-参见javac docs),那么编译的类字节码将不包含构造函数参数的名称。这意味着Spring不能使用反射来匹配构造函数参数名,因此需要按位置(即按索引)注入它们

    生成编译字节码以确保提供调试信息的是构建环境。一旦代码被编译,除了重新编译,您就无法检索这些信息

    另见What does the javac debugging information option -g:vars do?