本文整理了Java中javax.validation.Validation.buildDefaultValidatorFactory()
方法的一些代码示例,展示了Validation.buildDefaultValidatorFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validation.buildDefaultValidatorFactory()
方法的具体详情如下:
包路径:javax.validation.Validation
类名称:Validation
方法名:buildDefaultValidatorFactory
[英]Builds and returns a ValidatorFactory instance based on the default Bean Validation provider and following the XML configuration.
The provider list is resolved using the default validation provider resolver logic.
The code is semantically equivalent to Validation.byDefaultProvider().configure().buildValidatorFactory().
[中]
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new MethodValidationInterceptor using a default JSR-303 validator underneath.
*/
public MethodValidationInterceptor() {
this(Validation.buildDefaultValidatorFactory());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void afterPropertiesSet() {
if (this.validator == null) {
this.validator = Validation.buildDefaultValidatorFactory().getValidator();
}
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new MethodValidationInterceptor using a default JSR-303 validator underneath.
*/
public MethodValidationInterceptor() {
this(Validation.buildDefaultValidatorFactory());
}
代码示例来源:origin: org.springframework/spring-context
@Override
public void afterPropertiesSet() {
if (this.validator == null) {
this.validator = Validation.buildDefaultValidatorFactory().getValidator();
}
}
代码示例来源:origin: hs-web/hsweb-framework
public static Validator getValidator() {
if (validator == null) {
synchronized (BeanValidator.class) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
return validator = factory.getValidator();
}
}
return validator;
}
代码示例来源:origin: hs-web/hsweb-framework
@Bean(name = "validator")
@ConditionalOnMissingBean(Validator.class)
public Validator validator() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
return factory.getValidator();
}
代码示例来源:origin: apache/incubator-druid
@Override
public void configure(Binder binder)
{
binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
binder.bind(JsonConfigurator.class).in(LazySingleton.class);
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
protected void configure() {
// Validator instances are thread-safe and can be reused.
// See: http://hibernate.org/validator/documentation/getting-started/
//
// The Validator instance creation is quite expensive.
// Making this a Singleton reduced the CPU load by 50% and reduced the GC load from 5 GCs per second to 2 GCs
// per second when running a load test of the collector registration endpoint.
bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
}
}
代码示例来源:origin: hibernate/hibernate-orm
public void initialize(Map settings, ClassLoaderService classLoaderService) {
if ( !initialized ) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
init( factory, settings, classLoaderService );
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void configure(Binder binder)
{
binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
binder.bind(JsonConfigurator.class).in(LazySingleton.class);
binder.bind(Properties.class).toInstance(props);
}
},
代码示例来源:origin: apache/incubator-dubbo
@SuppressWarnings({"unchecked", "rawtypes"})
public JValidator(URL url) {
this.clazz = ReflectUtils.forName(url.getServiceInterface());
String jvalidation = url.getParameter("jvalidation");
ValidatorFactory factory;
if (jvalidation != null && jvalidation.length() > 0) {
factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory();
} else {
factory = Validation.buildDefaultValidatorFactory();
}
this.validator = factory.getValidator();
this.methodClassMap = new ConcurrentHashMap<String, Class>();
}
代码示例来源:origin: apache/incubator-dubbo
@SuppressWarnings({"unchecked", "rawtypes"})
public JValidator(URL url) {
this.clazz = ReflectUtils.forName(url.getServiceInterface());
String jvalidation = url.getParameter("jvalidation");
ValidatorFactory factory;
if (jvalidation != null && jvalidation.length() > 0) {
factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory();
} else {
factory = Validation.buildDefaultValidatorFactory();
}
this.validator = factory.getValidator();
this.methodClassMap = new ConcurrentHashMap<String, Class>();
}
代码示例来源:origin: apache/incubator-druid
@Override
public void configure(Binder binder)
{
binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
binder.bind(JsonConfigurator.class).in(LazySingleton.class);
binder.bind(Properties.class).toInstance(props);
}
},
代码示例来源:origin: apache/incubator-druid
@Override
public void configure(Binder binder)
{
Properties props = new Properties();
props.put("druid.emitter.composing.emitters", "[\"" + testEmitterType + "\"]");
binder.bind(Properties.class).toInstance(props);
binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
binder.bind(Emitter.class).annotatedWith(Names.named(testEmitterType)).toInstance(emitter);
}
},
代码示例来源:origin: spring-projects/spring-framework
@Override
public void afterPropertiesSet() {
if (this.validatorFactory == null) {
this.validatorFactory = Validation.buildDefaultValidatorFactory();
}
ValidatorContext validatorContext = this.validatorFactory.usingContext();
MessageInterpolator targetInterpolator = this.messageInterpolator;
if (targetInterpolator == null) {
targetInterpolator = this.validatorFactory.getMessageInterpolator();
}
validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
if (this.traversableResolver != null) {
validatorContext.traversableResolver(this.traversableResolver);
}
setTargetValidator(validatorContext.getValidator());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testNoLoggerAtAll()
{
final Properties properties = new Properties();
properties.setProperty("dummy", "unrelated");
final JsonConfigurator configurator = new JsonConfigurator(
mapper,
Validation.buildDefaultValidatorFactory()
.getValidator()
);
final RequestLoggerProvider provider = configurator.configurate(
properties,
"log",
RequestLoggerProvider.class,
NoopRequestLoggerProvider.class
);
Assert.assertThat(provider, CoreMatchers.instanceOf(NoopRequestLoggerProvider.class));
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testInvalidDelegateType()
{
final Properties properties = new Properties();
properties.setProperty("log.type", "filtered");
properties.setProperty("log.queryTimeThresholdMs", "100");
properties.setProperty("log.delegate.type", "nope");
final JsonConfigurator configurator = new JsonConfigurator(
mapper,
Validation.buildDefaultValidatorFactory()
.getValidator()
);
expectedException.expect(ProvisionException.class);
expectedException.expectMessage("Could not resolve type id 'nope'");
configurator.configurate(properties, "log", RequestLoggerProvider.class);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testNoDelegate()
{
final Properties properties = new Properties();
properties.setProperty("log.type", "filtered");
properties.setProperty("log.queryTimeThresholdMs", "100");
final JsonConfigurator configurator = new JsonConfigurator(
mapper,
Validation.buildDefaultValidatorFactory()
.getValidator()
);
expectedException.expect(ProvisionException.class);
expectedException.expectMessage("log.delegate - may not be null");
configurator.configurate(properties, "log", RequestLoggerProvider.class);
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testLoggerPropertiesWithNoType()
{
final Properties properties = new Properties();
properties.setProperty("dummy", "unrelated");
properties.setProperty("log.foo", "bar");
final JsonConfigurator configurator = new JsonConfigurator(
mapper,
Validation.buildDefaultValidatorFactory()
.getValidator()
);
expectedException.expect(ProvisionException.class);
expectedException.expectMessage("missing property 'type'");
configurator.configurate(
properties,
"log",
RequestLoggerProvider.class,
NoopRequestLoggerProvider.class
);
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public void afterPropertiesSet() {
if (this.validatorFactory == null) {
this.validatorFactory = Validation.buildDefaultValidatorFactory();
}
ValidatorContext validatorContext = this.validatorFactory.usingContext();
MessageInterpolator targetInterpolator = this.messageInterpolator;
if (targetInterpolator == null) {
targetInterpolator = this.validatorFactory.getMessageInterpolator();
}
validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
if (this.traversableResolver != null) {
validatorContext.traversableResolver(this.traversableResolver);
}
setTargetValidator(validatorContext.getValidator());
}
内容来源于网络,如有侵权,请联系作者删除!