17

I am using Spring Tool Suite to work with ReST services in Java. But at the very first point I am not able to start my first simple application. Please help. I am getting below error. [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

Below is my POM.xml file. The whole example is taken from JavaBrains tutorial on YouTube for reference purpose. I suspect some issue either with Environment or the Hibernate validation which i have not installed in my system.

<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);
    }

}
Rudresh Gaur
  • 171
  • 1
  • 1
  • 6
  • **Main file::** `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); } }` – Rudresh Gaur Jan 28 '18 at 04:23
  • 4
    You need to add follwoing depedenncy in you pom.xml:------ org.hibernate hibernate-validator – Dipak Thoke Jan 28 '18 at 06:27
  • Hi Dipak, Thank you for your comment. This time I added that tag also but still the issue is same. I have Eclipse and STS suite installed in my system at the same time. Can that e an issue? – Rudresh Gaur Jan 28 '18 at 09:37
  • Also by using spring-boot-starter-web, springboot downloads the hibernate validator dependency. As I can see it i Maven dependencies list – Rudresh Gaur Jan 28 '18 at 09:45
  • but can you see it in the generated jar file? – eis Jan 28 '18 at 10:42
  • also, update the question with your current pom.xml contents. – eis Jan 28 '18 at 10:43
  • @RudreshGaur remove com.bt.collab.alu.api.webapp.Application from pom.xml then it should work. – Dipak Thoke Jan 28 '18 at 16:55
  • Try to clean and update Your maven project Open project in eclipse - > right click -> update project -> select your project-> check the "offline" box and "update project/realese". – Dipak Thoke Jan 28 '18 at 17:03
  • Hi All, I considered all your suggestions but nothing is helping. Although I created using "New Spring Starter Project" option in STS tools suite and I am now able to do my stuff. – Rudresh Gaur Feb 04 '18 at 13:17

3 Answers3

34

In my case, I added the following dependency and its worked, Even I do not need any validation, maybe the Java update caused this issue.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Zhanzhou Ta
  • 458
  • 3
  • 5
6

Delete all files from <user_home>/.m2/repository and try "maven --> install project.

It seems that a file got corrupted. So in order to download the files correctly, try this procedure.

It should not be required to add any other dependencies at all. 'web' injects the validators that are missing.

Had the same issue here and it got solved by doing this procedure. You only need to do this once and then you will be good to go again. (sometimes - don't ask why - the local m2 repo gets corrupted).

Hope it helps. Regards, Ivan

Radi
  • 6,024
  • 16
  • 57
  • 86
  • Just adding `spring-boot-starter-validation` was also not sufficient for me to get my application running again. But I didn't need to delete the whole local maven repository. Deleting this folder was enough: `~/.m2/repository/org/hibernate/validator` – Ralf Jan 21 '21 at 11:33
3

I faced the same issue. My project has almost a year on production and this week I needed to make some changes, and for surprise, the project could not even be built. I solved the issue by adding the following dependency to my project.

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>${your-desired-version-matching-project-own}</version>
</dependency>

Note: I was using spring starters dependency, but still not loading that dependency.

  • 3
    Yes, this is a change in the latest Spring Boot. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#validation-starter-no-longer-included-in-web-starters – rougou May 26 '20 at 07:27