SpringBoot项目使用了@EnableAutoConfiguration 注解报错:The Bean Validation API is on the classpath but no impl

构建简单的SpringBoot项目时,在启动项目的时候发现如下错误:
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath

意思是Bean的校验API在classpath中没有找到实现的类。建议添加一个Validation 的实现,比如在classpath下添加一个Hibernate Validator的实现。 因为使用了 @EnableAutoConfiguration 注解,Spring则可能会尝试寻找一个关于Java specification for Bean Validation的实现 (更多详情请见: spring validation).

解决方案: 添加一个Hibernate Validator依赖实现。
在POM中添加

		<dependency>
		    <groupId>org.hibernate</groupId>
		    <artifactId>hibernate-validator</artifactId>
		    <version>5.3.0.Final</version>
		</dependency>

运行的示例代码程序如下:

package com.example.myproject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Hello world!
 *
 */
@RestController
@EnableAutoConfiguration
public class Example 
{
	
	@RequestMapping("/")
	String home() {
		return "Hello World!";
	}
	
    public static void main( String[] args )
    {
        SpringApplication.run(Example.class, args);
    }
}

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值