简体   繁体   English

JSP PropertyNotFoundException

[英]JSP PropertyNotFoundException

I have an Apache Tomcat + Hibernate based application. 我有一个基于Apache Tomcat + Hibernate的应用程序。 I have a class MyModel and a class MyViewModel which decorates an object of type MyModel. 我有一个MyModel类和一个MyViewModel类,它装饰了MyModel类型的对象。

When I get a request I return several instances of MyViewModel in the Map. 当我收到请求时,我在地图中返回MyViewModel的几个实例。 Lets say an instance is x. 可以说一个实例是x。 When i try to access ${x.comments} , I get a property not found exception. 当我尝试访问${x.comments} ,出现属性未找到异常。

I have double checked that MyModel contains a getComments() and setComments() method. 我有双重检查是为MyModel包含getComments()和setComments()方法。 Also MyViewModel contains getComments() method which invokes getComments() on the decorated object, returns empty string if null is returned. 此外,MyViewModel包含getComments()方法,该方法在装饰对象上调用getComments(),如果返回null,则返回空字符串。

Now the surprising part is that this code was working yesterday when I added the comments field everywhere in my code. 现在,令人惊讶的是,这个代码是昨天工作时,我在我的代码到处添加的注释字段。 My database still has the comments field. 我的数据库仍具有注释字段。 But somehow the bean is not being identified properly. 但是以某种方式无法正确识别该bean。

I have made some changes to the code and now I am using jquery-ui to get to the page but I don't see how that should make a difference as I can access all other fields except the comments field. 我已经对代码进行了一些更改,现在我正在使用jquery-ui进入页面,但是我看不到应该有什么不同,因为我可以访问除注释字段之外的所有其他字段。

The Hibernate logs show that the select query is not fetching the comments field. Hibernate日志显示选择查询未获取注释字段。

I tried restarting the server, my Eclipse IDE nothing seems to work. 我尝试重新启动服务器,但Eclipse IDE似乎没有任何作用。

Can you please help me identify the problem? 您能帮我找出问题吗?

Thanks in Advance! 提前致谢!

Fixed it! 修复!

The class MyViewModel was missing a default constructor. MyViewModel类缺少默认构造函数。

Why I could not catch it earlier? 为什么我不能早点抓到它?

I had an old set of jar files under WEB-INF/lib. 我在WEB-INF / lib下有一套旧的jar文件。 However when I configured the project in Eclipse I downloaded newer versions of the jar files in a separate directory and added them to the build path but my WEB-INF/lib still contained old jar files. 但是,当我在Eclipse中配置项目时,我将jar文件的较新版本下载到了单独的目录中,并将它们添加到了构建路径中,但是我的WEB-INF / lib仍然包含旧的jar文件。 I was eventually planning to have the new versions but since things were working fine I didn't bother. 我最终打算使用新版本,但是由于一切正常,所以我没有打扰。

Now somehow this was working yesterday but I might have done some sort of "cleanup" before committing. 现在,它以某种方式在昨天有效,但是在提交之前,我可能已经进行了某种“清理”。 I must have removed the default constructor from MyViewModel. 我必须从MyViewModel中删除了默认构造函数。 But I may not have restarted the server before testing it and hence it was working fine. 但是我可能没有在测试服务器之前重新启动服务器,因此它可以正常工作。

Ideally this should have been caught during deployment itself. 理想情况下,这应该在部署本身时就已捕获。 But somehow the new version of the jars was not catching the error. 但是以某种方式,新版本的罐子没有捕捉到错误。 When I switched to the jars in the WEB-INF/lib directory the server started throwing an exception during initialization saying that the default constructor is missing because of which the bean could not be initialized. 当我切换到WEB-INF / lib目录中的jars时,服务器在初始化期间开始引发异常,该异常表明缺少默认构造函数,因此无法初始化Bean。 This fixed the issue. 这解决了问题。

I tried to reproduce this situation. 我试图重现这种情况。 I removed the default constructor put the old .classpath file back in the project directory and it would not catch the error during deployment but it would fail at runtime. 我删除了默认构造函数,将旧的.classpath文件放回了项目目录,它不会在部署期间捕获错误,但会在运行时失败。 The reason was that a couple of dependencies in .classpath which were not required and could also not be satisfied. 原因是.classpath中的两个依赖关系不是必需的,也不能满足。 So Eclipse showed me a red exclamation mark (not the cross sign which usually indicates a build problem). 因此Eclipse为我显示了一个红色的感叹号(不是通常表示构建问题的十字符号)。 I now understand that the exclamation mark meant there was a validation error on my project and the project was not rebuilding as the build path contained missing dependencies. 我现在知道,感叹号表示我的项目上存在验证错误,并且该项目没有重建,因为构建路径包含缺少的依赖项。

So I removed the missing dependencies from my build path and the red exclamation mark disappeared. 因此,我从构建路径中删除了缺少的依赖项,红色的感叹号消失了。 Now the error was caught during deployment itself. 现在,在部署本身期间就捕获了错误。

So much for not using Maven. 不使用Maven太多了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM