我正在关注spring 3.0.5的HTTP 消息转换器,用于在控制器级别自动获取 java 对象。它适用于顺序请求。
但是当从服务器上的 REST 客户端发出并发请求时,java 对象出现不一致。我通过 REST 客户端发出相同类型的请求,但数据存在一些差异。
一些内部实例对象值变成了请求对象的空/空,甚至存在于 XML 中。(通过过滤器级别和控制器级别的日志验证)
注意一件事总是在对象的映射(键值对)中不一致。不知道这是什么原因。
我正在使用以下环境:
- 春天 3.0.5
- HTTP 消息转换器
- 雄猫 1.6
- jaxb 2.2
下面是xml的配置:
<bean id="messageAdapter"
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="marshallingHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter">
</bean>
控制器代码如下:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import com.sfnt.saas.provisioning.service.ProvisioningInterfaceManager;
import com.sfnt.saas.provisioning.util.messages.ContractData;
import com.sfnt.saas.provisioning.util.messages.ContractInfo;
@Controller
public class ProvisioningController {
private final Log log = LogFactory.getLog(this.getClass());
@Autowired
private ProvisioningInterfaceManager provisioningInterfaceManager;
@RequestMapping(value = {"/1.0/Contract"}, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void deployContract(HttpServletRequest request,
HttpServletResponse response, @RequestBody ContractData contractData)
throws RuntimeException {
ContractInfo contractInfo = null;
contractInfo = provisioningInterfaceManager
.deployContract(contractData);
response.addHeader("Location", request.getRequestURL() + "/"
+ contractInfo.getContract().getContract());
}
}
请帮忙 !!!