I have search and found a lot of topic on this issue, but for whatever reason the solutions does not solve my problem.
I am running Spring boot 1.5.8 and Hibernate.<
Please see below answers, I could reproduce this in my environment as well.
The validator being called twice, once the request is posted, another one is after the validation is done and entity gets persisted to DB, for the second time the autowired bean becomes null and throws NPE.
From the below answers, set validator property in entity manager along with other properties
<bean
id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence" />
</property>
<property name="jpaPropertyMap">
<map>
<entry key="javax.persistence.validation.factory" value-ref="validator" />
</map>
</property>
</bean>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
http://forum.spring.io/forum/spring-projects/web/84838-custom-jsr-303-validator-firing-twice
https://developer.jboss.org/thread/139770
How to inject spring bean into Validator(hibernate)
https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/additionalmodules.html