简体   繁体   English

package org.springframework.boot.test 不存在

[英]package org.springframework.boot.test does not exist

We are updating our spring boot from version to version 2.7.1我们正在将我们的 spring 引导从版本更新到版本 2.7.1

While building the code we are seeing package org.springframework.boot.test does not exist error.在构建代码时,我们看到 package org.springframework.boot.test does not exist 错误。

Below are the snippet of dependencies we have.以下是我们拥有的依赖项的片段。

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.1</version>
</parent>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-validator</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mongodb</groupId>
                    <artifactId>mongo-java-driver</artifactId>
                </exclusion>
                 <exclusion>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.17.2</version>
</dependency>
        
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.17.2</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.17.2</version>
</dependency> 
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-test</artifactId>
     <scope>test</scope>
     </dependency>
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

One of the file where we have contextconfiguration defined.我们定义了上下文配置的文件之一。 We have couple of more with similar annotations.我们还有几个带有类似注释的。

 @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = {
        ServicesConfig.class,
        RepositoryConfig.class,
        PropertySources.class,
        JmxConfig.class,
        UtilConfig.class,
        AsyncConfig.class,
        TenantIdentityConfig.class
})
@DirtiesContext
public abstract class AbstractAppInitializer {
}

Above are the dependencies I thought would be enough to have some analysis on.以上是我认为足以进行一些分析的依赖项。 If any other information required, please let me know.如果需要任何其他信息,请告诉我。

Update to Charlos.更新到查洛斯。 We already have spring-boot-starter-web defined in pom.xml我们已经在 pom.xml 中定义了 spring-boot-starter-web

 <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>log4j-over-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mongodb</groupId>
                <artifactId>mongo-java-driver</artifactId>
            </exclusion>
             <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-json</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

try adding this dependency:尝试添加此依赖项:

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

and remove the exclusions..并删除排除项..

OR ...或者 ...

You just need to check your Pom.xml and make sure your spring-boot-starter-data-jpa line is uncommented.您只需要检查您的 Pom.xml 并确保您的 spring-boot-starter-data-jpa 行未注释。 You must have pring-boot-starter-data-jpa uncommented in your pom.xml file.您必须在 pom.xml 文件中取消注释 pring-boot-starter-data-jpa。 If you dont have then just add it.如果你没有,那么只需添加它。

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

it woks?可以吗? tell me :-)告诉我 :-)

You should give the error message and the code, then we can see what's going on there.你应该给出错误信息和代码,然后我们就可以看到那里发生了什么。 I have got a same error, for me,我有同样的错误,对我来说,

the compile error gives the line number which let me know the line:编译错误给出了让我知道该行的行号:

import org.springframework.boot.test.SpringApplicationConfiguration which requried by @SpringApplicationConfiguration and check the doc https://docs.spring.io/spring-boot/docs/1.4.x/api/org/springframework/boot/test/SpringApplicationConfiguration.html , apparently it's deprecated. import org.springframework.boot.test.SpringApplicationConfiguration @SpringApplicationConfiguration检查文档https://docs.spring.io/spring-boot/docs/1.4.x/api/org/springframework/boot/test/SpringApplicationConfiguration .html ,显然它已被弃用。 So if you upgrade to a new version spring-boot and have new associated spring-boot-test dependency, this class is not there any longer.因此,如果您升级到新版本 spring-boot 并具有新的关联 spring-boot-test 依赖项,则此 class 将不再存在。 You need to replace the annotation @SpringApplicationConfiguration with @SpringBootTest .您需要将注释@SpringApplicationConfiguration替换为@SpringBootTest You can check it, and have a try.你可以检查一下,试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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