spring boot 中使用 hibernate validate 校验
spring boot 中使用 Hibernate validate 进行入参字段校验,一般用于web 接口入参校验,用起来非常方便。
spring boot 的配置123456789101112131415161718192021222324252627282930313233343536373839404142import org.hibernate.validator.HibernateValidator;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;import javax.validation.Validation;import javax.validation.Validator;import javax.validation.Valid ...
解决 Cannot determine embedded database driver class for database type NONE
刚搭的新项目一启动就报错,一直就知种起不来。各种搜索以后总结两种解决方式。先看错误:
1234567Description:Cannot determine embedded database driver class for database type NONEAction:If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
处理方式一:排除两个默认配置
1@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
结论:没用
处理方式二: 可行 ...
springboot注解 @ConfigurationProperties和@EnableConfigurationProperties的区别
区别@EnableConfigurationProperties测试发现 @ConfigurationProperties 与 @EnableConfigurationProperties 关系特别大。
@EnableConfigurationProperties 文档中解释:当@EnableConfigurationProperties注解应用到你的@Configuration时,任何被@ConfigurationProperties注解的beans将自动被Environment属性配置。这种风格的配置特别适合与SpringApplication的外部YAML配置进行配合使用。
测试发现:1.使用 @EnableConfigurationProperties 进行注册
1234567891011121314151617181920212223242526272829@ConfigurationProperties(prefix = "service.properties")public class HelloServiceProperties { ...