如果我在控制器类中返回一个Employee对象,我会收到来自REST服务的响应。但是如果我试图返回一个List,那么我经常会收到这个错误:
错误:在提交响应后无法调用senderror() (还附上图片) 我正在使用Eclipse,tomcat,maven和Spring REST服务。
这是我的Controller类代码片段,它正在返回Employee,一切都很好,我可以在浏览器上看到我的JSON数据。但是当我将Employee更改为List作为我的新返回类型时,我收到以下错误,我的Eclipse也会挂起几分钟。我认为我的问题可能与JSON转换器有关。请帮忙。
@Controller
@RequestMapping("/emp")
public class EMPController {
@Autowired
EmployeeService empservice;
@RequestMapping("byname3/{name}")
@ResponseBody
public Employee getByName(@PathVariable String name) {
System.out.println("Inside getByName()..successfully..EMPController");
.....
......
我的dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.spice.controller" />
<context:component-scan base-package="com.spice.daoImpl" />
<context:component-scan base-package="com.spice.serviceImpl " />
<mvc:annotation-driven /> <!-- tHIS HELPS IN AUTOMATIC JSON-TO-JAVA AND VICE VERSA CONVERTUION -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"></property>
<property name="username" value="tiwari"></property>
<property name="password" value="tiwari"></property>
</bean>
<bean id="mysessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- eARLIER i WAS USING org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean -->
<!-- BUT THIS LEADS TO SOME CACHE PROVIDER CLASS NOT FOUND EXCEPTION -->
<!-- ALSO THIS AnnotationSessionFactoryBean IS NOW REPLACED BY LocalSessionFactoryBean -->
<property name="dataSource" ref="dataSource"></property>
<property name="annotatedClasses">
<list>
<value>com.spice.beans.Employee</value>
<value>com.spice.beans.Address</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<!-- THIS CLASS IS COMPATIBLE WITH ABOVE VERSIONS OF SPRING AND HIBERNATE -->
<property name="sessionFactory" ref="mysessionFactory" />
</bean>
</beans>
答案 0 :(得分:0)
错误:在提交响应后无法调用senderror() (也附在图片上)
此错误是另一个错误的后果。服务器遇到了应用程序的主要异常,因此它试图调用HttpServletResponse#sendError(),它依次抛出IllegalStateException。