problem description
deployment projects an and bjord tomcat under tomcat deploy a first, then b.
two projects are logged in using login in LoginController respectively. Xtuser uses @ Validated to verify the parameter userid passed in the front end. A project can be verified, and bindingResult reports an error when b project is verified: Property "userId" threw exception; nested exception is java.lang.NullPointerException;
but if you deploy the b project separately, there is nothing wrong with the verification, so ask for advice.
related codes
/ / 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);//10
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 related configuration
<!-- -->
<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>