springMVC中bindingResult报java.lang.NullPointerException?
"
tomcat下部署项目a和b,tomcat先部署a,后部署b。
两个项目分别使用LoginController中的login完成登录,其中xtuser使用@Validated完成前端传入参数userid的校验,a项目可以校验通过,b项目校验时bindingResult报错:Property 'userId' threw exception; nested exception is java.lang.NullPointerException;
但是单独部署b项目,校验又不出任何问题,求大神指点?
// LoginController.java
@RequestMapping(value="/login", method = RequestMethod.GET)
public void login( @Validated({IXtLoginGroup.class}) XtUser xtUser,BindingResult bindingResult
,@RequestParam(value ="token_index", required = true)String token_index
, HttpServletRequest request,HttpServletResponse response) throws Exception {
if(bindingResult.hasFieldErrors()){
String messageStr=ExceptionMessager.extractMessagesFromExceptionList(bindingResult);
try {
Map map=new HashMap();
map.put("code", 0);//1为正常,0为错误
map.put("message", "fault");
Map childMap=new HashMap();
childMap.put("title", "服务端校验错误");
childMap.put("errorMsg",messageStr);
map.put("data",childMap);
System.out.println( JsonTool.Obj2Json(map));
ResponseUtil.write(response, JsonTool.Obj2Json(map));
return;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//XtUser.java
public class XtUser implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@NotEmpty(message="用户账号{notNull}",groups={IXtUserGroup.class,IXtLoginGroup.class})
private String userId;
}
//spring相关配置
<!-- 默认的注解映射的支持 -->
<mvc:annotation-driven validator="validator" conversion-service="conversion-service" />
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
<!--不设置则默认为classpath下的 ValidationMessages.properties -->
<property name="validationMessageSource" ref="validatemessageSource"/>
</bean>
<bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
<bean id="validatemessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:validatemessages"/>
<!-- <property name="useCodeAsDefaultMessage" value="true" /> -->
<property name="defaultEncoding" value="utf-8" />
<property name="cacheSeconds" value="120"/>
</bean>
"
"
public void setUserId(String userId) throws Exception { this.userId = userId; //加密userId,作为界面返回controller的定位参数
this.userId_encoded=SM2Util.encrypt(userId);
System.out.println("***********"+userId);
//this.userId_encoded=userId;
}
由于SM2Util错误使用了静态块生成公私钥,导致b项目中公私钥为空,entity中setUserId下SM2Util.encrypt()方法没有成功执行完成,导致数据绑定报错!
"
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。