问题的具体详情和这位老外描述是一样的
http://forum.springsource.org/showthread.php?t=67257
即抛出异常
引用
java.lang.IllegalStateException: WebApplicationObjectSupport instance [org.springframework.web.servlet.view.velocity.Velo cityView: name 'view'; URL [/WEB-INF/velocity/view.vm]] does not run within a ServletContext. Make sure the object is fully configured!
最后跟调试(关于Liferay远程调试Java Remote Debug和热部署HotDeploy的Eclipse开发环境配置有空再写上来)跟代码发现
if (servletContext == null && isContextRequired()) {
throw new IllegalStateException("WebApplicationObjectSupport instance [" + this +
"] does not run within a ServletContext. Make sure the object is fully configured!");
}
这里抛出的,
isContextRequired(),这个方法返回的是true(被VelocityView的父类AbstactTemplateView重写了)
一开始我以为getServletContext()==null 我一直以为是Liferay Portal的原因,所以就没考虑从这里解决问题.
我尝试写一个VelocityView的子类MyVelocityView,把isContextRequired()重写成return true;来尝试是否能恢复
但是重写后仍然调用VelocityView而不是MyVelocityView,开始怀疑是否是liferay自带的spring的加载顺序优先与自己项目的.(呃 具体说不清原理,感觉有这可能,有看客讲得清的欢迎斧正)
然后再看spring配置,突然发现没有配置Listener
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/{你配置文件名}.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
加上后问题解决了,因为这下getServletContext()!=null 了
==========回顾问题=================
为什么没有用velocity前,我的spring(IoC/MVC)作用正常呢
1.因为liferay会吧/WEB-INF/{你的portlet名称}-portlet.xml当作spring的Context加载进去
所以spring的运作正常
2.因为之前我用的是InternalResourceViewResolver,而它的isContextRequired() return false.
===========问题小总结================
记得web.xml里要配置好ContextLoaderListener
对于Portal来说ViewRendererServlet必须的,用来复用spring MVC的视图处理
=========篇外话===============
此外, 发现Spring-referrance中有一处小Typo错误哈
Chapter 16.4 Velocity & FreeMarker -- Contextconfiguration
代码下面有行小字
引用
Note
Fornonweb-appsadda VelocityConfigurationFactoryBean ora
FreeMarkerConfigurationFactoryBean toyourapplicationcontextdefinitionfile.
其中VelocityConfigurationFactoryBean 应该是写错了 没有这个类(FreeMarkerConfigurationFactoryBean )倒是有的
正确的应该是VelocityEngineFactoryBean
热烈欢迎对本文任何错误含糊之处斧正拍砖!
分享到:
相关推荐
Liferay Spring Portlet MVC 使用 Maven 的 Liferay Spring Portlet MVC 项目模板。 Liferay EE 6.2.10.11 (GA1, SP710) Java 1.7 小门户 2.0 弹簧框架 4.1.5 基于注解的控制器配置 用法 $ git clone ...
liferay portal 开发指南liferay portal 开发指南liferay portal 开发指南liferay portal 开发指南
里面有四个小型的liferay portal mvc实例,所需要的jar文件大家可以在eclipse里面新建一个portlet项目,再将里面的实例代码拷贝进去即可运行
Using Liferay Portal 6.1
Liferay Portal 内容管理
liferay Portal 学习书籍,外国人编写的,非常好。
包含liferay portal开发,帮助,架构,代码,等portlet中文文档 ,PDF格式
基于Liferay+Portal技术的校园信息门户研究与实现
liferay portal 6文档,使用说明
Liferay Portal Liferay IDE
liferay portal system development 高清pdf
关于liferay portal介绍的ppt
Liferay Portal数据库读写说明
liferay是一个现成的,即开即用的,功能完备的门户网站Liferay Portal,是一个完美的桌面协同办公组合,完全为企业和机构设计
Liferay Portal 二次开发指南,内容比较详细。
[Packt Publishing] Liferay Portal 性能调优最佳实践 (英文版) [Packt Publishing] Liferay Portal Performance Best Practices (E-Book) ☆ 出版信息:☆ [作者信息] Samir Bhatt [出版机构] Packt Publishing...
我最近由于工作需要在学习PORTAL开发,公司用的是LIFERAY的,因此上网找了些资料,贡献给大家!希望对喜欢LIFERAY PORTAL的开发人员有用!!
Liferay Portal 二次开发指南 pdf格式,本文从Liferay Portal的架构入手,详细讲解Portal的用户策略、内容布局、桌面和品质的要素,引导读者完成Liferay Portal初步的二次开发,在Liferay Portal上定制自己的Portlet...
非常好的Liferay Portal 开发资料,基于v5.2.x版本,packt网站售价$50的,强烈推荐! 欢迎高手与我一起交流liferay的相关二次开发技术。 QQ:258184782 Liferay portal is one of the most mature portal frameworks...
liferay + struts2 + spring + ibatis整合开发案例,可以正常运行,供大家参考和学习