I started with generating my application using JHipster v.3.5.1.
After some time, I needed to create validator to perform some business logic validation on my entity, when it is created with POST. So I made:
@Component
public class MyValidator implements Validator
Then, I tried to inject it into my controller (annotated with @RestController), but no matter which way I tried, it always resulted in something like that:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.my.app.service.domain.MyValidator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
Ways I tried to create bean and inject it
@Autowired
private MyValidator myValidator;
@Inject
private MyValidator myValidator;
@Autowired
@Qualifier("myValidator")
private MyValidator myValidator; (with @Component("myValidator") on class)
@Inject
@Qualifier("myValidator")
private MyValidator myValidator; (with @Component("myValidator") on class)
//Below was inserted in class annotated with @Configuration
@Bean
public MyValidator myValidator() {
return new MyValidator();
}
However I tried it - it failed. I always got NoSuchBeanDefinitionException or field value was set to null.
I've also checked class location in project structure. To be 100% percent sure it's well placed, I've put it in package the with @Services, which are scanned and work well. No effect.
I know that it seems to be pretty easy task and I know this injection is possible (I've seen it done in project in my work), but somehow I'm not able to make it work in my project.
Maybe I'm missing something in configuration? Thanks for any help :)