多视图处理下的懒加载

最近遇到最多的一个问题是懒加载在render View的时候无法取得值的问题。懒加载处理对象有两种代理模式,jdk动态代理[默认]和cglib编织字节码代理。
HTTP Status 500 - Unable to locate object to be marshalled in model: {member=memberid|1 name|lily phone|1356874584 email|[email protected], org.springframework.validation.BindingResult.member=org.springframework.validation.BeanPropertyBindingResult: 0 errors}
org.springframework.web.servlet.view.xml.MarshallingView.renderMergedOutputModel(MarshallingView.java:104)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
如上是返回xml视图时报错
多视图处理下的懒加载_第1张图片
如上是对象信息,返回对象经过懒加载封装,在视图取值时就会报错
		<dependency>
		      <groupId>com.fasterxml.jackson.datatype</groupId>
		      <artifactId>jackson-datatype-hibernate3</artifactId>
		      <version>2.0.0</version>
		</dependency>

然后找到fasterXML,用于处理json数据显示时的懒加载,但是xml还没找到相似功能的模块。
 <property name="defaultViews">
            <list>
            	<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
            		<property name="objectMapper">
	                    <bean class="org.carryli.common.hibernate.MyObjectMapper" />
	                </property>
            	</bean>
        </list>
</property>


貌似是spring在3.2使用fasterxml处理懒加载
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate3.Hibernate3Module;

@Component
public class MyObjectMapper  extends ObjectMapper {

	public MyObjectMapper() {
		Hibernate3Module hbm = new Hibernate3Module();
		hbm.enable(Hibernate3Module.Feature.FORCE_LAZY_LOADING);

		registerModule(hbm);
		configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
	}

	public void setPrettyPrint(boolean prettyPrint) {
		configure(SerializationFeature.INDENT_OUTPUT, prettyPrint);
	}
}

以上作为记录

你可能感兴趣的:(spring,xml,json,Hibernate)