简体   繁体   中英

Why doesn't my Spring Boot starter bring its dependencies to the project?

I've created a simple starter - TimeStarter with RestController inside. Here is its pom:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.0</version>
    <relativePath/>
</parent>

<groupId>ez</groupId>
<artifactId>time-starter-spring-boot-starter</artifactId>
<version>0.0.1</version>
<name>time-starter</name>

<properties>
    <java.version>11</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

I've added TimeStarter to my project:

<dependencies>
    <dependency>
        <groupId>ez</groupId>
        <artifactId>time-starter-spring-boot-starter</artifactId>
        <version>0.0.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

After that I expect that all necessary dependencies (spring-boot-starter-web) will appear in my project, and the REST controller from starter will be ready for HTTP requests. But no, I have to add spring-boot-starter-web and spring-web dependencies to make my starter work.

As M.Deinum said, the reason was I made my dependencies in starter "optional".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM