无法导入org.springframework.test.context.ActiveProfiles;

沃尔夫冈

亲爱的,

我无法导入“ org.springframework.test.context.ActiveProfiles”。我正在导入它以使用@ActiveProfiles批注。

我在pom.xml中添加了以下依赖项,也清理了项目并更新了Maven,但导入ActiveProfiles时仍然收到错误。

这是我的pom.xml:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>offer21</groupId>
    <artifactId>offer21</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>5.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.2.8.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jcl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.5.4-Final</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.1.5.Final</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.7</version>
        </dependency>


        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>5.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>5.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.8.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

依存关系:
在此处输入图片说明

另外,在检查依赖关系层次结构时,我注意到spring-test和junit处于灰色。我不知道为什么在此处输入图片说明

感谢您的帮助。

丹尼尔·陶布(Daniel Taub)

问题在于:

<sourceDirectory>src</sourceDirectory>

你需要设置testSourceDirectory以及

<sourceDirectory>src/main</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

导入org.springframework.test.context.junit4.SpringJUnit4ClassRunner无法解析

替换导入org.springframework.test.context.transaction.TransactionConfiguration; 在Spring Test 4.3.1版本中?

冲突 org.springframework.boot.test.context.SpringBootTest; 和 org.springframework.test.context.junit.jupiter.SpringExtension;

Maven:NoClassDefFoundError:org.springframework.test.context.junit4.SpringJUnit4ClassRunner

春季4-找到了接口org.springframework.test.context.TestContext,但是期望使用类

春季测试:为org.springframework.test.context.jdbc.Sql配置数据源

控制器org.springframework.context.NoSuchMessageException中的Springboot Mockito Test和Autowired messageSource

无法解析org.springframework.context.support.GenericApplicationContext类型

ClassNotFoundException :: org.springframework.web.context.ContextLoaderListener

“导入org.springframework无法解析。”

导入org.springframework.security无法解析

缺少工件org.springframework:spring-context:jar:$ {org.springframework-version}

无法实例化接口org.springframework.context.ApplicationContextInitializer(Spring 5.2.3 + Spring Boot 2.2.3)

无法启动Tomcat的嵌入式org.springframework.context.ApplicationContextException

Spring-Boot-Maven-Plugin,无法实例化接口org.springframework.context.ApplicationContextInitializer

添加spring-security-oauth2后无法实例化接口org.springframework.context.ApplicationListener

无法初始化类org.springframework.web.context.request.ServletRequestAttributes

找不到org.springframework.web.context.ContextLoaderListener类

java.lang.NoClassDefFoundError:org / springframework / context / ApplicationContext maven

找不到类org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration]

java.lang.NoClassDefFoundError:org / springframework / web / context / ContextCleanupListener问题

java.lang.ClassNotFoundException:org.springframework.context.ApplicationContextInitializer

java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

找不到类org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer

在TomEE中部署org.springframework.context.ApplicationListener异常

导入org.springframework.boot.autoconfigure.web.ErrorAttributes无法解析

导入org.springframework.data无法在gradle中解析

无法导入 org.springframework.web.multipart.MultipartFile;

无法导入org.springframework.data.rest.webmvc.ResourceNotFoundException;