5

I created spring boot project(Spring starter project) on STS(Spring tool suit), both of Window and Mac. Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </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-tomcat</artifactId>
            <scope>provided</scope>
        </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>

Some of the dependency hierarchies are missing on Mac.

Example :

hibernate-validator

  • validation-api (missing on Mac)
  • jboss-loggin (missing on Mac)
  • classmate (missing on Mac)

I need that jars on Mac without modifying pom.xml. I think I miss some environment Mac.

And I bought Mac 2 days ago. It's my first Mac.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
jin
  • 59
  • 1
  • 1
  • 3
  • It isn't missing, it isn't in your pom. What isn't in your pom cannot be there. Add the starter to your pom else it won't be included. – M. Deinum Sep 29 '17 at 05:51
  • spring boot starter web dependency already includes hibernate validator dependency. – Vijay Mar 22 '18 at 14:03

1 Answers1

23

If you want to use Hibernate Validator, you need to include it as explicit dependency:

    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>

Notice we don't specify version as Spring Boot will take care of it.

Other option is to use validation starter provided by Spring Boot:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

Concerning your Windows/MacOS specific problems, it is some kind of misunderstanding. You need dependencies I mentioned. If you include them, it will work the same way on both platforms.

java-addict301
  • 3,220
  • 2
  • 25
  • 37
luboskrnac
  • 23,973
  • 10
  • 81
  • 92
  • but dependencies are available on Window 10 without specify dependency – jin Sep 29 '17 at 11:41
  • hibernate-validator is not problem. it's dependencies are problem. macbookair macOS 10.12.6 – jin Sep 29 '17 at 11:44
  • No, it's not dependencies problem nor platform specific problem. You are just missing validation dependencies in your pom.xml file. – luboskrnac Sep 29 '17 at 11:50
  • @jin I suggest install a plugin named `maven-dependency-plugin` in your part of pom. Then use `mvn -Dverbose dependency:tree` to see if the hibernate validator is getting listed. I strongly believe that the hibernate validator is a transitive dependency of 'spring-boot-starter-web' and you should see that in the dependency tree. – vijayakumarpsg587 Oct 10 '18 at 13:30
  • is it a risk to define both: `spring-boot-starter-validation` and an old `hibernate.validator` depdency ? – bvdb Jul 02 '20 at 22:35
  • I guess some risk of versions incompatibility can be there, but you would need to combine hibernate-validator version with breaking changes against one used by spring starter. – luboskrnac Jul 08 '20 at 13:06