Создаю аннотацию для валидации
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {OperandTypeComparisonValidator.class})
@Documented
public @interface ValidOperandTypeComparison {
String message() default "com.validation.ValidPatternRows.message";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
и имплементация
public class OperandTypeComparisonValidator implements ConstraintValidator<ValidOperandTypeComparison, Pattern> {
@Autowired
private EventDefinitionService eventDefinitionService;
@Override
public void initialize(ValidOperandTypeComparison constraintAnnotation) {
}
@Override
public boolean isValid(Pattern pattern, ConstraintValidatorContext constraintValidatorContext) {
SequentialPattern sequentialPattern = (SequentialPattern) pattern;
List<SequentialPatternRow> rows = sequentialPattern.getRows();
SequentialPatternRow row1 = rows.get(1);
BinaryExpression expression1 = (BinaryExpression) row1.getNewConditions();
Rule rule1 = row1.getRule();
String eventId1 = rule1.getEventDefinitionId();
EventDefinition eventDefinition1 = eventDefinitionService.get(eventId1);
и конфигурация в Application
@SpringBootApplication
@EnableSwagger2
@EnableDiscoveryClient
@EnableScheduling
public class Application {
@Autowired
private Environment env;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public LocalValidatorFactoryBean validatorFactory() {
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
factoryBean.setProviderClass(HibernateValidator.class);
factoryBean.setValidationMessageSource(messageSource());
factoryBean.afterPropertiesSet();
return factoryBean;
}
Не получается сделать Autowired сервиса. Как это сделать?
Пример дебагера