Spring boot Spring Boot Maven插件错误-运行时发生异常。null:NullPointerException
运行项目时,我收到以下错误消息Spring boot Spring Boot Maven插件错误-运行时发生异常。null:NullPointerException,spring-boot,kotlin,Spring Boot,Kotlin,运行项目时,我收到以下错误消息[ERROR]无法执行目标org.springframework.boot:spring boot maven plugin:2.0.2.RELEASE:run(默认cli)on project KotlinJwt:运行时发生异常。null:NullPointerException->[Help 1] 日志 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://m
[ERROR]无法执行目标org.springframework.boot:spring boot maven plugin:2.0.2.RELEASE:run(默认cli)on project KotlinJwt:运行时发生异常。null:NullPointerException->[Help 1]
日志
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>KotlinJwt</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>KotlinJwt</name>
<description>Spring Boot Kotlin REST API Example</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.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>
<kotlin.version>1.2.41</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.demo.KotlinJwtApplication</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.example
. 起初,SpringBootMaven插件中似乎并没有mainClass标记,但并没有抛出mainClassfound错误李>
其他代码:对于Kotlin,主类应该是顶级函数,因此替换
@SpringBootApplication
class KotlinJwtApplication {
@Bean
fun bCryptPasswordEncoder() : BCryptPasswordEncoder {
return BCryptPasswordEncoder()
}
fun main(args: Array<String>) {
runApplication<KotlinJwtApplication>(*args)
}
}
@springboot应用程序
类kotlinjwt应用程序{
@豆子
有趣的bCryptPasswordEncoder():bCryptPasswordEncoder{
返回BCryptPasswordEncoder()
}
趣味主线(args:Array){
运行应用程序(*args)
}
}
与
@springboot应用程序
类kotlinjwt应用程序{
@豆子
有趣的bCryptPasswordEncoder():bCryptPasswordEncoder{
返回BCryptPasswordEncoder()
}
}
趣味主线(args:Array){
运行应用程序(*args)
}
然后,您还可以删除
<configuration>
<mainClass>com.example.demo.KotlinJwtApplication</mainClass>
</configuration>
com.example.demo.KotlinJwtApplication
从您pom.xml
@SpringBootApplication
class KotlinJwtApplication {
@Bean
fun bCryptPasswordEncoder() : BCryptPasswordEncoder {
return BCryptPasswordEncoder()
}
fun main(args: Array<String>) {
runApplication<KotlinJwtApplication>(*args)
}
}
@SpringBootApplication
class KotlinJwtApplication {
@Bean
fun bCryptPasswordEncoder() : BCryptPasswordEncoder {
return BCryptPasswordEncoder()
}
}
fun main(args: Array<String>) {
runApplication<KotlinJwtApplication>(*args)
}
<configuration>
<mainClass>com.example.demo.KotlinJwtApplication</mainClass>
</configuration>