OGNL类关键字处理问题:Java代码转OGNL报错求助
Fixing OGNL Class Reference Error for
getDeclaredFields() Let's break down what's going wrong and how to fix it:
The Root Cause
Your original OGNL code includes .class after the class name, which clashes with OGNL's syntax rules. When you write @SomeClass.class@getDeclaredFields(), OGNL tries to look up a class literally named SomeClass.class—which doesn't exist, hence the ClassNotFoundException you're seeing.
Correct OGNL Syntax
OGNL uses @[Full Class Name]@ to reference a Class object directly, so you don't need to append .class at all. Here's the right way to write your expression:
For a class in the default package
@SomeClass@getDeclaredFields()
For a class with a package (e.g., com.example.SomeClass)
@com.example.SomeClass@getDeclaredFields()
Quick Additional Tip
This same syntax works for other static class operations too:
- Access a static field:
@SomeClass@MY_STATIC_FIELD - Call a static method with parameters:
@SomeClass@myStaticMethod("param1", 123)
内容的提问来源于stack exchange,提问作者user482745
相关产品推荐
相关产品推荐

