當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalValidatorFactoryBean類代碼示例

本文整理匯總了Java中org.springframework.validation.beanvalidation.LocalValidatorFactoryBean的典型用法代碼示例。如果您正苦於以下問題:Java LocalValidatorFactoryBean類的具體用法?Java LocalValidatorFactoryBean怎麽用?Java LocalValidatorFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalValidatorFactoryBean類屬於org.springframework.validation.beanvalidation包,在下文中一共展示了LocalValidatorFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: entityManagerFactory

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
    DataSource dataSource,
    MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
    CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
    LocalValidatorFactoryBean localValidatorFactoryBean) {

    Map<String, Object> properties = new HashMap<>();
    properties.putAll(jpaProperties.getHibernateProperties(dataSource));
    properties.put(MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    properties.put(MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
    properties.put(MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
    properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan(JPA_PACKAGES);
    em.setJpaVendorAdapter(jpaVendorAdapter());
    em.setJpaPropertyMap(properties);
    return em;
}
 
開發者ID:xm-online,項目名稱:xm-ms-balance,代碼行數:22,代碼來源:DatabaseConfiguration.java

示例2: requestMappingHandlerAdapter

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {

	delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
	RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	ConversionService initializerConversionService = initializer.getConversionService();
	assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);

	verify(webMvcConfigurer).configureMessageConverters(converters.capture());
	verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
	verify(webMvcConfigurer).addFormatters(conversionService.capture());
	verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
	verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
	verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());

	assertSame(conversionService.getValue(), initializerConversionService);
	assertEquals(0, resolvers.getValue().size());
	assertEquals(0, handlers.getValue().size());
	assertEquals(converters.getValue(), adapter.getMessageConverters());
	assertNotNull(asyncConfigurer);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:DelegatingWebMvcConfigurationTests.java

示例3: testSimpleValidation

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSimpleValidation() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ValidatorFactoryTests.java

示例4: testSimpleValidationWithCustomProvider

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ValidatorFactoryTests.java

示例5: testSpringValidationWithClassLevel

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSpringValidationWithClassLevel() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.setName("Juergen");
	person.getAddress().setStreet("Juergen's Street");
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(1, result.getErrorCount());
	ObjectError globalError = result.getGlobalError();
	List<String> errorCodes = Arrays.asList(globalError.getCodes());
	assertEquals(2, errorCodes.size());
	assertTrue(errorCodes.contains("NameAddressValid.person"));
	assertTrue(errorCodes.contains("NameAddressValid"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ValidatorFactoryTests.java

示例6: testSpringValidationWithAutowiredValidator

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSpringValidationWithAutowiredValidator() throws Exception {
	ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(
			LocalValidatorFactoryBean.class);
	LocalValidatorFactoryBean validator = ctx.getBean(LocalValidatorFactoryBean.class);

	ValidPerson person = new ValidPerson();
	person.expectsAutowiredValidator = true;
	person.setName("Juergen");
	person.getAddress().setStreet("Juergen's Street");
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(1, result.getErrorCount());
	ObjectError globalError = result.getGlobalError();
	List<String> errorCodes = Arrays.asList(globalError.getCodes());
	assertEquals(2, errorCodes.size());
	assertTrue(errorCodes.contains("NameAddressValid.person"));
	assertTrue(errorCodes.contains("NameAddressValid"));
	ctx.close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ValidatorFactoryTests.java

示例7: testSpringValidationWithErrorInListElement

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSpringValidationWithErrorInListElement() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.getAddressList().add(new ValidAddress());
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(3, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	fieldError = result.getFieldError("addressList[0].street");
	assertEquals("addressList[0].street", fieldError.getField());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ValidatorFactoryTests.java

示例8: testSpringValidationWithErrorInSetElement

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void testSpringValidationWithErrorInSetElement() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	person.getAddressSet().add(new ValidAddress());
	BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
	validator.validate(person, result);
	assertEquals(3, result.getErrorCount());
	FieldError fieldError = result.getFieldError("name");
	assertEquals("name", fieldError.getField());
	fieldError = result.getFieldError("address.street");
	assertEquals("address.street", fieldError.getField());
	fieldError = result.getFieldError("addressSet[].street");
	assertEquals("addressSet[].street", fieldError.getField());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ValidatorFactoryTests.java

示例9: setUp

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    EventValidator.ValidationConfig validationConfig = new EventValidator.ValidationConfig();
    validationConfig.setEnvironment(Mockito.mock(Environment.class));
    EventValidator.setValidationConfig(validationConfig);

    this.validator = new LocalValidatorFactoryBean();
    validator.afterPropertiesSet();

    EntityFactory entityFactory = new HibEntityFactory();
    EntityConverter entityConverter = new EntityConverter(entityFactory);
    this.converter = new ContentConverter(entityConverter);

    instanceUnderTest = new SimpleUrlContentReader(converter, null, validator, 700, instanceProvider);
}
 
開發者ID:1and1,項目名稱:cosmo,代碼行數:17,代碼來源:SimpleUrlContentReaderTest.java

示例10: requestMappingHandlerAdapter

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {
	RequestMappingHandlerAdapter adapter = mvcConfiguration.requestMappingHandlerAdapter();

	List<HttpMessageConverter<?>> expectedConverters = new ArrayList<HttpMessageConverter<?>>();
	mvcConfiguration.addDefaultHttpMessageConverters(expectedConverters);
	assertEquals(expectedConverters.size(), adapter.getMessageConverters().size());

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	assertNotNull(initializer);

	ConversionService conversionService = initializer.getConversionService();
	assertNotNull(conversionService);
	assertTrue(conversionService instanceof FormattingConversionService);

	Validator validator = initializer.getValidator();
	assertNotNull(validator);
	assertTrue(validator instanceof LocalValidatorFactoryBean);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:20,代碼來源:WebMvcConfigurationSupportTests.java

示例11: setUp

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Before
public void setUp(){
 
 currentUser.setProxyUser("admin", "test", new String[] {"VIEW_ENTITY", "CREATE_ENTITY"});
 
 assertNotNull(headOfHouseholdService);
 
    localValidatorFactory = new LocalValidatorFactoryBean();
    localValidatorFactory.setProviderClass(HibernateValidator.class);
    localValidatorFactory.afterPropertiesSet();
    
    oldHoh = genericDao.findByProperty(Individual.class, "extId", "NBAS1I"); 
    newHoh = genericDao.findByProperty(Individual.class, "extId", "BJOH1J");
 visit = genericDao.findByProperty(Visit.class, "extId", "VLOCMBI11J");
 fieldWorker = genericDao.findByProperty(FieldWorker.class, "extId", "FWEK1D");
 socialGroup = genericDao.findByProperty(SocialGroup.class, "extId", "MBI1", false);
    
 assertNotNull(oldHoh);
 assertNotNull(newHoh);
 assertNotNull(visit);
 assertNotNull(fieldWorker);
 assertNotNull(socialGroup);
}
 
開發者ID:OpenHDS,項目名稱:openhds-server,代碼行數:24,代碼來源:HeadOfHouseholdTest.java

示例12: localValidatorFactoryBean

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean() {
    HibernateValidatorConfigurationStrategy strategy = Optional.ofNullable(hibernateValidatorConfigurationStrategy)
                                                               .orElseGet(() -> configuration -> {
                                                               });
    List<? extends ConstraintValidator> validators = Optional.ofNullable(this.validators)
                                                             .orElseGet(Collections::emptyList);
    return new CustomLocalValidatorFactoryBean(strategy, validators);
}
 
開發者ID:infobip,項目名稱:infobip-bean-validation,代碼行數:10,代碼來源:BeanValidationAutoConfiguration.java

示例13: entityManagerFactory

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
                                                                   MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
                                                                   CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
                                                                   LocalValidatorFactoryBean localValidatorFactoryBean) {
    Map<String, Object> properties = new HashMap<>();
    properties.putAll(jpaProperties.getHibernateProperties(dataSource));
    properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    properties
        .put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
    properties
        .put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);

    properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);

    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan(JPA_PACKAGES);
    em.setJpaVendorAdapter(jpaVendorAdapter());
    em.setJpaPropertyMap(properties);
    return em;
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:23,代碼來源:DatabaseConfiguration.java

示例14: validator

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
/**
 * Custom validator.
 * @param messageSource {@link MessageSource}
 * @return de {@link Validator}
 */
@Bean
public Validator validator(MessageSource messageSource) {
    LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean();
    factory.setValidationMessageSource(messageSource);
    return factory;
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:BeheerWebApplication.java

示例15: getValidator

import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; //導入依賴的package包/類
@Override
public Validator getValidator() {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setValidationMessageSource(messageSource);

	return validator;
}
 
開發者ID:edylle,項目名稱:pathological-reports,代碼行數:8,代碼來源:PathologicalReportsApplication.java


注:本文中的org.springframework.validation.beanvalidation.LocalValidatorFactoryBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。