【发布时间】:2017-08-13 00:21:38
【问题描述】:
我正在尝试将 Kotlin 与 Spring 5.0 一起使用,但是我遇到了 Kotlin 编译器无法识别对 Spring 的任何引用的问题:
[ERROR] 未能执行目标 org.jetbrains.kotlin:kotlin-maven-plugin:1.1.1:compile (compile) on project kotlin-mvc-project:编译失败:编译失败:
[ERROR](文件位置):[7,12]未解决的参考:springframework
我正在使用 Spring 里程碑版本 Spring 5.0.0.M5 和 Kotlin 版本 1.1.1(在我的 kotlin 编译器和 IntelliJ Kotlin 插件上)。在我的任何 Kotlin 文件中,IDE 都没有突出显示编译错误,但运行 kotlin-compiler 似乎根本看不到 Spring 5.0。
有没有人知道如何解决这个问题?我在这个项目中使用 Maven,我附上了我的 POM 以供参考:
<?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>kotlin-mvc-project</groupId>
<artifactId>kotlin-mvc-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version>1.1.1</kotlin.version>
<spring.version>5.0.0.M5</spring.version>
</properties>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
能否请您发布发生错误的文件部分?
-
抱歉,不确定您指的是什么文件?在调用 mvn clean install 后运行 kotlin-compiler 时出现这些错误
-
我现在已经设法通过回滚到 Spring 的当前发布版本来解决这个问题。 4.3.7.发布。不知道为什么我不能让 5.0 工作
-
[ERROR] (file location):[7,12] Unresolved reference: springframework我的意思是这个错误——发生这种情况的行是什么? -
对了。它只是导入 org.springframework.context.annotation.Bean;代码中每个对 spring 对象的引用都会出现其中一个错误。