我正在使用Spring Tool Suite在Java中使用ReST服务。但是在第一点上,我无法启动我的第一个简单应用程序。请帮忙。我得到以下错误。[Using Java8, STS suite, Ubuntu 16.04, $Java_Home:/usr/lib/jvm/java-8-oracle
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
2018-01-28 09:37:14.658 INFO 7971 --- [ main] i.j.springbootstarter.CourseApiApp : Starting CourseApiApp on rudresh-Vostro-14-3468 with PID 7971 (/home/rudresh/Documents/workspace-sts-3.9.2.RELEASE/course-api/target/classes started by rudresh in /home/rudresh/Documents/workspace-sts-3.9.2.RELEASE/course-api)
2018-01-28 09:37:14.667 INFO 7971 --- [ main] i.j.springbootstarter.CourseApiApp : No active profile set, falling back to default profiles: default
2018-01-28 09:37:14.827 INFO 7971 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6dde5c8c: startup date [Sun Jan 28 09:37:14 IST 2018]; root of context hierarchy
2018-01-28 09:37:16.551 WARN 7971 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.http.encoding-org.springframework.boot.autoconfigure.web.HttpEncodingProperties': Initialization of bean failed; nested exception is javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2018-01-28 09:37:16.552 INFO 7971 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-01-28 09:37:16.568 INFO 7971 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-28 09:37:16.578 ERROR 7971 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
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
下面是我的POM.xml文件。整个示例取自YouTube上的JavaBrains教程,以供参考。我怀疑环境或休眠验证存在一些问题,我没有在我的系统中安装。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.javabrains.springbootquickstart</groupId>
<artifactId>course-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Course Api</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
"This is main class to start SpringBoot application. Although it does not do anything but it should at least redirect to browser Error page."
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(CourseApiApp.class, args);
}
}
就我而言,我添加了以下依赖项及其工作,即使我不需要任何验证,也许 Java 更新导致了这个问题。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
从项目中删除<user_home>/.m2/repository and try "maven --> install
所有文件。
文件似乎已损坏。因此,为了正确下载文件,请尝试此过程。
根本不需要添加任何其他依赖项。"web"注入缺少的验证器。
这里有同样的问题,通过执行此过程解决了。你只需要这样做一次,然后你就可以再去一次了。(有时 - 不要问为什么 - 本地 M2 存储库损坏(。
希望对您有所帮助。问候,Ivan
我遇到了同样的问题。我的项目已经生产了将近一年,本周我需要进行一些更改,令人惊讶的是,该项目甚至无法构建。我通过将以下依赖项添加到我的项目中解决了这个问题。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${your-desired-version-matching-project-own}</version>
</dependency>
注意:我正在使用弹簧启动器依赖项,但仍然没有加载该依赖项。
这很旧,但以下内容对我有用。
注释 格拉德尔
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version:'2.7.8'
exclude(module: 'spring-boot-starter-logging')
exclude(module: 'spring-boot-starter-tomcat')
希望这对某人有所帮助。