How do get around a javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: in Spring

javax validation validationexception hv000063 unable to instantiate
spring boot conditional validation
hv000028: unexpected exception during isvalid call.
javax validation validationexception hv000090: unable to access
javax validation custom validator
javax validation validationexception hv000065: unable to load class
hv000033: at least one custom message must be created if the default error message gets disabled
mockmvc unable to instantiate constraintvalidator

Anyone ever worked with spring-boot and run into this error.

javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator:
**<more stack...>**
Caused by: java.lang.NoSuchMethodException: 
com.comapany.package.validator.<init>()

I know it has something to do with this:

Any constraint implementations relying on ConstraintValidatorFactory behaviors specific to an implementation (dependency injection, no no-arg constructor and so on) are not considered portable.

but my Validator cannot be portable because it requires the repo to work so that is not an option.

I have tried adding a no-args constructor to my validator but then i get this:

javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.
Caused by: java.lang.NullPointerException

I have also tried to override the LocalValidatorFactoryBean:

@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean(ConstraintValidatorFactory validatorFactory) {
        var bean = new LocalValidatorFactoryBean();
        bean.setConstraintValidatorFactory(validatorFactory);
        return bean;
    }

and even though Spring recognizes my factory, I still get that error(HV000064).

Another option would be to add a concrete Repo in my no-args constructor for my validator, but that feels wrong.

public Validator(){
    repo = new ConcreteClassOfRepository();
}

So how do I proceed?

EDIT (reuested code):

ValidatorCode

@Service
@AllArgsConstructor
@NoArgsConstructor
public class UniqueIdValidator implements ConstraintValidator<UniqueId, String> {

    @Autowired
    private SampleRepository repo;


    @Override
    public void initialize(UniqueId constraintAnnotation) {

    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return !repo.existsById(s);
    }

}

StackTrace

javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.

    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:177)
    at org.hibernate.validator.internal.engine.constraintvalidation.SimpleConstraintTree.validateConstraints(SimpleConstraintTree.java:68)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:73)
    at org.hibernate.validator.internal.metadata.core.MetaConstraint.doValidateConstraint(MetaConstraint.java:127)
    at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:120)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:552)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:515)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:485)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:447)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:397)
    at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:173)
    at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:116)
    at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:80)
    at org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:211)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:84)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
    at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
    at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
    at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:57)
    at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:108)
    at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1309)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1389)
    at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1558)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1526)
    at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1574)
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById(SimpleJpaRepository.java:327)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:371)
    at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:204)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:657)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:621)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy112.existsById(Unknown Source)
    at com.packageName.ValidationTest.trackingBugCausedByValidatorNotPortable(ValidationTest.java:99)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.NullPointerException
    at com.packageName.UniqueIdValidator.isValid(UniqueIdValidator.java:27)
    at com.packageName.UniqueIdValidator.isValid(UniqueIdValidator.java:11)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:171)

SampleRepository

@Repository
public interface SampleRepository extends JpaRepository<SampleEntity, String> {

}

Tracking Test

    @Test
    void trackingBugCausedByValidatorNotPortable() {
        var entity = new SampleEntity();
        entity.setId("an id");
        repo.save(entity);
        repo.delete(entity);
        assertTrue(repo.existsById("an id"));
        fail("Add @UniqueId to SampleEntity and run");
    }

repo.save() is successful, repo.delete() is successful, but repo.existsById() breaks with the aforementioned exception

CustomConstraintValidatorFactory & ImplementationFactory

public class CustomConstraintValidatorFactory implements ConstraintValidatorFactory {

    private final ConstraintValidatorFactory defaultFactory;
    private final ImplementationFactory[] implementations;

    public CustomConstraintValidatorFactory(ConstraintValidatorFactory defaultFactory, ImplementationFactory... implementations) {
        this.defaultFactory = defaultFactory;
        this.implementations = implementations;
    }

    @Override
    public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
        return Arrays.stream(implementations)
            .filter(factory -> factory.supports(key))
            .findFirst()
            .map(ImplementationFactory::create)
            .map(v -> (T) v)
            .orElseGet(() -> defaultFactory.getInstance(key));
    }

    @Override
    public void releaseInstance(ConstraintValidator<?, ?> instance) {
    }
}

public class InheritanceMatchValidatorFactory implements ImplementationFactory {

    Class klass;
    Supplier<ConstraintValidator> validator;

    @Override
    public boolean supports(Class key) {
        return klass.isAssignableFrom(key);
    }

    @Override
    public ConstraintValidator<?, ?> create() {
        return validator.get();
    }

}

can you try implementing SpringConstraintValidatorFactory in your test class and injecting application context also remove the @AllArgsConstructor @NoArgsConstructor before trying.

@Import({Validator.class})
@ContextConfiguration(classes = Application.class)
public class Test {
    private LocalValidatorFactoryBean validator;

    @Autowired
    private ConfigurableApplicationContext applicationContext;

    @BeforeEach
    void initialize() {
        SpringConstraintValidatorFactory springConstraintValidatorFactory
                = new SpringConstraintValidatorFactory(
                applicationContext.getAutowireCapableBeanFactory());
        validator = new LocalValidatorFactoryBean();
        validator.setConstraintValidatorFactory(springConstraintValidatorFactory);
        validator.setApplicationContext(applicationContext);
        validator.afterPropertiesSet();
    }
    @Test
    void testValidator(){
        //call the validator here
    }
}

javax.validation.ValidationException: HV000064: Unable to , ValidationException: HV000064: Unable to instantiate In order to use the repository, you can add the Validator as a service. Then the implements ConstraintValidator<UniqueStorePoolConstraint, The framework instantiates them and wires all dependencies like the class was a regular Spring bean. 4 How do get around a javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: in Spring Jan 6 3 How to manually call onSaveInstanceState() Jun 8 '17 3 AVD failing to run on Android Studios Feb 7 '15

man this question is a mess. Not explained what you're trying to do. You call method on repo, which does not exist there(did you mean CrudRepository?), unless you defined it on your own, and then it should have been shown. Entity is not shown. The actual issue is not pointed at ...

So it seems that your SampleRepository is not autowired. Most probably it is because your

public LocalValidatorFactoryBean localValidatorFactoryBean(ConstraintValidatorFactory validatorFactory)

just sets there a default ConstraintValidatorFactoryImpl class, which just creates validator instance using no-arg constructor via reflection and no injection takes place. Could you verify if it's not the case? If so, you need to find some strategy which does injection (is it SpringConstraintValidatorFactory maybe?) and set this one, ie. try to declare SpringConstraintValidatorFactory bean and use that bean to set LocalValidatorFactoryBean.

But it's just a guess, I don't understand this question sufficiently.

spring-cloud/spring-cloud-contract, Caused by: javax.validation.ValidationException: HV000064: Unable to instantiate ConstraintValidator: com.nexenio.thanos.validation. The reason that it cannot created is, that I autowire stuff into that Validator and do not provide a default do I really have to? trying to get around a weird requirement. Spring Boot 2 allows to inject Bean in custom Validator without any fuss.The Spring framework automatically detects all classes which implement the ConstraintValidator interface, instantiate them, and wire all dependencies. I had Similar problem , this is how i have implemented. Step 1 Interface

Error stack is NPE

Caused by: java.lang.NullPointerException
    at com.packageName.UniqueIdValidator.isValid(UniqueIdValidator.java:27)
    at com.packageName.UniqueIdValidator.isValid(UniqueIdValidator.java:11)

All you have to do is make sure your String s object is not null while calling isValid()

maybe you can do this

@Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return (!s.isEmpty ? !repo.existsById(s) : false);
    }

In addition to this you should also make sure your repo object is not null as well, One thing I advice is to create constructor with your repo object rather than @Autowire it.

@Service
@AllArgsConstructor
@NoArgsConstructor
public class UniqueIdValidator implements ConstraintValidator<UniqueId, String> {

    private final SampleRepository sampleRepository;

    public void UniqueIdValidator(SampleRepository sampleRepository){
         this.sampleRepository = sampleRepository;
    }

    @Override
    public void initialize(UniqueId constraintAnnotation) {

    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        return !repo.existsById(s);
    }

}

Chapter 3. Creating custom constraints, Let's write a constraint annotation, that can be used to express that a given string on to the licensePlate field of the Car class from Chapter 1, Getting started to ensure, Next, we need to implement a constraint validator, that's able to validate you can disable the default error message generation and add a custom error� JAX-RS, JSR-311, is a new JCP specification that provides a Java API for RESTful Web Services over the HTTP protocol. Resteasy is an portable implementation of this specification which can run in any Servlet container.

[#SPR-13327] Provide a , ValidationException: HV000064: Unable to instantiate constraint factory class: class Spring document does not refer to the constraint-validator-factory property, or even to the file (as in your last code snippet) and inject a javax. validation. buildDefaultValidatorFactory() which bypass Spring completely. RESTEasy is bundled with WildFly and completely integrated as per the requirements of Java EE. You can use it with EJB and CDI and you can rely completely on WildFly to scan for and deploy your JAX-RS services and providers.

Bean Validation: Integrating JSR-303 with Spring, As the developer of the Bean Validation Framework for Spring (part of The work on it started around one and a half years ago as an attempt http:// repository.jboss.com/maven2/javax/validation/validation-api/1.0. 25, throw new RuntimeException( "Could not instantiate constraint validator class '" + key. Resteasy Reference Guide en US - Free ebook download as PDF File (.pdf), Text File (.txt) or read book online for free. resteasy-reference-guide

Java Code Examples for javax.validation.ValidationException, This page shows Java code examples of javax.validation. Validation API is in the classpath, " + "but default ValidatorFactory can not be built. getTreatments() .get(0)); assertFalse(original. Source Project: spring-analysis-note Source File: SpringValidatorAdapter.java License: MIT License, 5 votes, vote down vote up�

Comments
  • Can you share your validator code? Also the NPE stacktrace would be helpful.
  • @akortex91 that's been added
  • could be similar to stackoverflow.com/questions/51915592/…
  • @kbluue ValidationException: HV000064: Unable to instantiate this occurs during running the tests ?
  • @ManojKrishna yes during the tests
  • I'm currently using @SpringBootTest, do I have to swap it out for @ContextConfiguration(classes = MySpringApplicaton.class). Otherwise, private ConfigurableApplicationContext applicationContext; behaves exactly the same.
  • @org.springframework.stereotype.Repository public interface SampleRepository extends Repository<SampleEntity, String> @Test void trackingBugCausedByValidatorNotPortable() { var entity = new SampleEntity(); entity.setId("an id"); repo.save(entity); repo.delete(entity); assertTrue(repo.existsById("something")); } The error javax.validation.ValidationException: HV000028: Unexpected exception during isValid call. is thrown in the existsById() line. I hope this helps.
  • IIUC you got NPE there, and existsById does not throw NPE. So your repo is null there. Meaning that it's not injected. Which ConstraintValidatorFactory is injected into your config method named localValidatorFactoryBean?
  • Whichever I choose. I've tried injecting my own factory into localValidatorFactoryBean (see in question) and overriding the ConstraintValidatorFactory but neither works. I will update question with my tracking test and see if I can walk you through the process.
  • so which one is used? What is injected in ConstraintValidatorFactory validatorFactory? I mean you set it as bean.setConstraintValidatorFactory(validatorFactory); but what is validatorFactory??? Instance of what class is it?
  • A custom built instance of ConstraintValidatorFactory
  • the repo is null in the isValid(). What I need to do is figure out how to autowire repo properly when Spring instantializes the validator.
  • You're right, I just checked and the string is null too. This could be a configuration error.
  • @kbluue you can overcome empty string NPE with condition I posted in answer but for null repo I will need to peek into your SampleRepository class - can you please edit question with SampleRepository code?
  • what is your service class looks like, have to annotated it with @Service. Here's couple of reason why your repo object could be null moreofless.co.uk/…