I am currently working on retrieving data from a database using Sprng 3.2 and myBatis with the goal of receiving the data in JSON format.
In order to achieve this, I have included jackson-core-asl, jackson-core-lgpl, and jackson-mapper-asl(1.9.13) in the pom.xml file.
However, upon sending a request to the server, I encountered an error message stating "HTTP Status 404 - /WEB-INF/jsp/listJson.jsp". This issue has caused me to question why my configuration file is not functioning properly for @ResponseBody.
Despite conducting extensive research online, I have been unable to resolve the error thus far. Could it be possible that this setup does not work as expected on Spring 3.2?
Interestingly, when I replaced <mvc:annotation-driven />
with the following code snippet:
<beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</beans:list>
</beans:property>
This change led to successful results. However, it should be noted that AnnotationMethodHandlerAdapter is deprecated in Spring 3.2.
- servlet-context.xml
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
2 Controller
@Controller
public class BoardController
{
@Autowired
private MainService mainService;
@RequestMapping("/listJson.do")
public @ResponseBody
Map<?, ?> listJson(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable
{
model.put("results", mainService.getList(paramMap));
return model;
}
}