前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringBoot项目使用了@EnableAutoConfiguration 注解报错:The Bean Validation API is on the classpath but no impl

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

作者头像
青山师
发布2023-05-05 17:33:42
6100
发布2023-05-05 17:33:42
举报

构建简单的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中添加

代码语言:javascript
复制
		<dependency>
		    <groupId>org.hibernate</groupId>
		    <artifactId>hibernate-validator</artifactId>
		    <version>5.3.0.Final</version>
		</dependency>

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

代码语言:javascript
复制
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);
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-07-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档