我环顾四周,但无法弄清楚我在尝试获取结果的 xml 视图时错过了什么。
以下是我得到的例外:
javax.servlet.ServletException: Unable to locate object to be marshalled in model: {movies=[com.wickedlynotsmart.imdb.model.Movie@1450f1f, com.wickedlynotsmart.imdb.model.Movie@ac622a, com.wickedlynotsmart.imdb.model.Movie@160c21a, com.wickedlynotsmart.imdb.model.Movie@1677737, com.wickedlynotsmart.imdb.model.Movie@1c3dc66]}
at org.springframework.web.servlet.view.xml.MarshallingView.renderMergedOutputModel(MarshallingView.java:100)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
...
...
以下是处理请求时包含的文件:
servlet 应用程序上下文文件
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.wickedlynotsmart.imdb.model.Movie</value>
</list>
</property>
</bean>
<bean id="movies" class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg ref="jaxbMarshaller" />
</bean>
领域对象
@Entity
@XmlRootElement
public class Movie implements Serializable {
public Movie() {}
//interesting stuff
}
控制器
@RequestMapping("/movies")
public class MoviesController {
private static final Log logger = LogFactory.getLog(MoviesController.class);
@Autowired
private MovieManagementService movieManagementService;
@RequestMapping(method=RequestMethod.GET)
public String findAllMovies(Model model) {
List<Movie> movies = movieManagementService.getAllMovies();
model.addAttribute("movies", movies);
return "movies";
}
//interesting stuff
}
有人可以帮我解决我在这里可能缺少的东西吗?
谢谢。
编辑:我基本上是想查看 BeanNameViewResolver 的运行情况,我已经在配置文件中配置了 BeanNameViewResolver,如下所示:
<bean id="beanNameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value="2" />
</bean>